@proxze/kyc-react-native 0.1.0 → 0.2.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/README.md CHANGED
@@ -19,9 +19,18 @@ on Android, CoreLocation region monitoring on iOS. It is an **optional** peer:
19
19
  a bank with its own location stack can implement the `LocationAdapter`
20
20
  interface instead and skip the dependency entirely.
21
21
 
22
- `@react-native-async-storage/async-storage` persists the offline event queue.
23
- Also optional — without it the queue lives in memory only (events survive
24
- connectivity loss but not a process kill).
22
+ `@react-native-async-storage/async-storage` persists the offline event queue
23
+ and the record of which verification this device is tracking, which is how
24
+ tracking resumes after a relaunch. Also optional — without it both live in
25
+ memory only, and the customer is taken back to the permission step after the
26
+ app is killed.
27
+
28
+ **Android release builds need a Transistorsoft license** in
29
+ `AndroidManifest.xml` (`com.transistorsoft.locationmanager.license`). Debug
30
+ builds work without one; a release build without one does not track at all.
31
+
32
+ Needs a proxze-kyc-service that serves `POST /v2/sdk/locations`, the endpoint
33
+ the location library syncs to natively.
25
34
 
26
35
  ## Security model
27
36
 
@@ -33,6 +42,31 @@ verification. The bank's `pxz_live_…` API key stays on the bank's backend:
33
42
  3. The app drives this SDK with that token; the token can only report evidence
34
43
  for its own session and dies when the verification completes.
35
44
 
45
+ ## App setup (once, at launch)
46
+
47
+ Two calls belong at the root of the app, not on a screen:
48
+
49
+ ```js
50
+ // index.js
51
+ import { AppRegistry } from 'react-native';
52
+ import {
53
+ registerProxzeKycHeadlessTask,
54
+ restoreProxzeKycTracking,
55
+ } from '@proxze/kyc-react-native';
56
+ import App from './App';
57
+
58
+ // Android: keeps taking night-time fixes after the app is swiped away.
59
+ registerProxzeKycHeadlessTask();
60
+ // Re-arms tracking on every launch, including the background launches iOS
61
+ // performs when the phone crosses the fence. A no-op when nothing is tracking.
62
+ restoreProxzeKycTracking();
63
+
64
+ AppRegistry.registerComponent('App', () => App);
65
+ ```
66
+
67
+ The location library allows one headless task per app. If yours already
68
+ registers one, call `handleProxzeKycHeadlessEvent(event)` from it instead.
69
+
36
70
  ## Quickstart
37
71
 
38
72
  ```tsx
@@ -40,7 +74,8 @@ import { useProxzeKyc } from '@proxze/kyc-react-native';
40
74
 
41
75
  function AddressVerification({ sessionToken }: { sessionToken: string }) {
42
76
  const { session, state, loading, kyc } = useProxzeKyc({
43
- baseUrl: 'https://api.proxze.com',
77
+ // The KYC API host the bank's backend initiated the verification on.
78
+ baseUrl: KYC_API_BASE_URL,
44
79
  sessionToken,
45
80
  });
46
81
 
@@ -89,23 +124,47 @@ function AddressVerification({ sessionToken }: { sessionToken: string }) {
89
124
 
90
125
  Imperative use without React is the same machine: `new ProxzeKycSession({...})`.
91
126
 
127
+ **Tracking belongs to the verification, not to the screen.** Once started it
128
+ keeps running while the app is closed, and `bootstrap()` resumes it on the next
129
+ launch without asking for permission again (the state goes straight to
130
+ `tracking`). Unmounting the screen only detaches listeners. It ends when the
131
+ verification closes, or when the app calls `kyc.stopTracking()` because the
132
+ customer abandoned it.
133
+
134
+ `baseUrl` must be the environment the bank's backend initiated the
135
+ verification on. A token from one environment is refused by the other with a
136
+ 401, which the SDK treats as a closed verification: it stops and reports
137
+ `completed`.
138
+
92
139
  ## How night tracking works
93
140
 
94
141
  The server evaluates nights in **hybrid** mode and this SDK feeds both models:
95
142
 
96
143
  - **Geofence transitions** (`enter`/`exit`/`dwell`) come from the OS and
97
144
  survive app termination and reboots (`stopOnTerminate: false`,
98
- `startOnBoot: true`).
99
- - **Pings** are sampled on the 30-minute marks inside the 12AM–5AM window
100
- (Africa/Lagos), where the OS allows. iOS will not run a 30-minute background
101
- timer — that's expected; the transitions plus the **morning check** (one
102
- in-fence sample in the 3 hours after 05:00) satisfy the server's
103
- arrived-and-stayed strategy.
104
- - Everything is queued offline-first and flushed in batches; the server
105
- dedupes on `clientEventId`, so replays are harmless.
145
+ `startOnBoot: true`). A phone already inside the fence when it is
146
+ registered reports an `enter` straight away.
147
+ - **Pings** are taken by a 30-minute heartbeat, but only inside the 12AM–5AM
148
+ window (Africa/Lagos) and the three-hour **morning check** after it. No fixes
149
+ are taken during the day, and the library runs in geofences-only mode, so
150
+ the customer's movements are never recorded.
151
+ - **Delivery is native.** The location library stores every transition and
152
+ fix and posts them to `/v2/sdk/locations` itself, so events reach the server
153
+ while the app is in the background, killed or rebooting. Undelivered records
154
+ wait on the device (up to 30 days) and are retried; the server dedupes on
155
+ the library's record id. Custom adapters without native delivery fall back
156
+ to the SDK's JavaScript queue, which only runs while the app is alive.
157
+ - **iOS** only fires the heartbeat in the background with `preventSuspend`,
158
+ which the default adapter enables (`iosPreventSuspend: false` turns it off,
159
+ at the cost of iPhones sending nothing overnight for someone who stays home).
160
+ It costs battery for the length of the verification window.
106
161
  - Android's mock-location flag rides along on every event; spoofed nights are
107
162
  flagged server-side.
108
163
 
164
+ `kyc.diagnostics()` reports what is actually happening on the device: the
165
+ permission grade, whether the OS still holds the fence, records waiting to be
166
+ delivered, and the HTTP status of the last native sync.
167
+
109
168
  ## Evidence uploads
110
169
 
111
170
  ```ts
@@ -142,7 +201,7 @@ what each state means for their verification:
142
201
  | State | Effect | App should |
143
202
  | --- | --- | --- |
144
203
  | `granted_always` + precise | Full night tracking | Nothing — happy path |
145
- | `granted_when_in_use` | Fence events only while app foregrounded; nights mostly inconclusive | Prompt to upgrade to "Allow all the time" (Android takes the user to settings for this on 11+) |
204
+ | `granted_when_in_use` | Fence events only while app foregrounded; nights mostly inconclusive | Prompt to upgrade to "Allow all the time". On Android 11+ the default adapter shows a rationale dialog that opens settings (`backgroundPermissionRationale` to change its copy) |
146
205
  | `precise: false` | Approximate fixes are km-wide; a 100m fence can never confirm | Walk the user to settings → enable Precise Location |
147
206
  | `denied` | No tracking at all | Explain, re-prompt, or offer to cancel the verification |
148
207
 
package/dist/client.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { BillUploadResponse, ConfirmAddressResponse, ConsentResponse, IngestResponse, LocationEventInput, RestartResponse, RNFile, SdkSession, UtilityDocumentType, VideoMeta, VideoUploadResponse } from './types';
2
2
  export interface ProxzeKycClientOptions {
3
- /** e.g. `https://api.proxze.com` — no trailing slash, no `/v2`. */
3
+ /**
4
+ * The KYC API host the verification was initiated on — no trailing slash,
5
+ * no `/v2`. A token from one environment is refused (401) by another.
6
+ */
4
7
  baseUrl: string;
5
8
  /** The `session_token` the bank's backend received from `POST /v2/kyc/initiate`. */
6
9
  sessionToken: string;
@@ -16,7 +19,7 @@ export declare class ProxzeKycError extends Error {
16
19
  status: number, body?: unknown | undefined);
17
20
  /** Session finished / token expired — stop tracking, nothing to retry. */
18
21
  get isSessionClosed(): boolean;
19
- /** Worth retrying later (offline, timeout, 5xx). */
22
+ /** Worth retrying later (offline, timeout, 5xx, rate limited). */
20
23
  get isTransient(): boolean;
21
24
  }
22
25
  /**
package/dist/client.js CHANGED
@@ -14,9 +14,12 @@ class ProxzeKycError extends Error {
14
14
  get isSessionClosed() {
15
15
  return this.status === 401;
16
16
  }
17
- /** Worth retrying later (offline, timeout, 5xx). */
17
+ /** Worth retrying later (offline, timeout, 5xx, rate limited). */
18
18
  get isTransient() {
19
- return this.status === 0 || this.status >= 500 || this.status === 429;
19
+ return (this.status === 0 ||
20
+ this.status >= 500 ||
21
+ this.status === 429 ||
22
+ this.status === 408);
20
23
  }
21
24
  }
22
25
  exports.ProxzeKycError = ProxzeKycError;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The identifier the SDK registers its geofence under. The server's native
3
+ * sync endpoint only accepts transitions for this fence, so must match
4
+ * `SDK_GEOFENCE_IDENTIFIER` in proxze-kyc-service.
5
+ */
6
+ export declare const SDK_GEOFENCE_IDENTIFIER = "proxze-kyc-residence";
7
+ /** Native sync endpoint, relative to the API base URL. */
8
+ export declare const NATIVE_SYNC_PATH = "/v2/sdk/locations";
9
+ /** Storage key for the active verification, so tracking survives a relaunch. */
10
+ export declare const TRACKING_RECORD_KEY = "@proxze-kyc/tracking";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TRACKING_RECORD_KEY = exports.NATIVE_SYNC_PATH = exports.SDK_GEOFENCE_IDENTIFIER = void 0;
4
+ /**
5
+ * The identifier the SDK registers its geofence under. The server's native
6
+ * sync endpoint only accepts transitions for this fence, so must match
7
+ * `SDK_GEOFENCE_IDENTIFIER` in proxze-kyc-service.
8
+ */
9
+ exports.SDK_GEOFENCE_IDENTIFIER = 'proxze-kyc-residence';
10
+ /** Native sync endpoint, relative to the API base URL. */
11
+ exports.NATIVE_SYNC_PATH = '/v2/sdk/locations';
12
+ /** Storage key for the active verification, so tracking survives a relaunch. */
13
+ exports.TRACKING_RECORD_KEY = '@proxze-kyc/tracking';
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Android: what the default adapter needs to keep sampling after the app has
3
+ * been killed.
4
+ *
5
+ * With `stopOnTerminate: false` the location library keeps running natively
6
+ * when the customer swipes the app away, and syncs geofence transitions on
7
+ * its own. The heartbeat, though, only reaches JavaScript through a headless
8
+ * task, and the heartbeat is what takes the night-window fixes. Without this,
9
+ * a killed app reports transitions but no pings.
10
+ *
11
+ * Call once, at module scope in the app's `index.js`, next to
12
+ * `AppRegistry.registerComponent`:
13
+ *
14
+ * ```js
15
+ * import { registerProxzeKycHeadlessTask } from '@proxze/kyc-react-native';
16
+ * registerProxzeKycHeadlessTask();
17
+ * ```
18
+ *
19
+ * The library allows one headless task per app. If the app already registers
20
+ * its own, call {@link handleProxzeKycHeadlessEvent} from it instead.
21
+ */
22
+ export declare const registerProxzeKycHeadlessTask: () => void;
23
+ /** The SDK's share of a headless event, for apps with their own headless task. */
24
+ export declare const handleProxzeKycHeadlessEvent: (event: {
25
+ name?: string;
26
+ params?: unknown;
27
+ }, bg?: any) => Promise<void>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleProxzeKycHeadlessEvent = exports.registerProxzeKycHeadlessTask = void 0;
4
+ const backgroundGeolocationAdapter_1 = require("./location/backgroundGeolocationAdapter");
5
+ /**
6
+ * Android: what the default adapter needs to keep sampling after the app has
7
+ * been killed.
8
+ *
9
+ * With `stopOnTerminate: false` the location library keeps running natively
10
+ * when the customer swipes the app away, and syncs geofence transitions on
11
+ * its own. The heartbeat, though, only reaches JavaScript through a headless
12
+ * task, and the heartbeat is what takes the night-window fixes. Without this,
13
+ * a killed app reports transitions but no pings.
14
+ *
15
+ * Call once, at module scope in the app's `index.js`, next to
16
+ * `AppRegistry.registerComponent`:
17
+ *
18
+ * ```js
19
+ * import { registerProxzeKycHeadlessTask } from '@proxze/kyc-react-native';
20
+ * registerProxzeKycHeadlessTask();
21
+ * ```
22
+ *
23
+ * The library allows one headless task per app. If the app already registers
24
+ * its own, call {@link handleProxzeKycHeadlessEvent} from it instead.
25
+ */
26
+ const registerProxzeKycHeadlessTask = () => {
27
+ const bg = loadPlugin();
28
+ bg.registerHeadlessTask((event) => (0, exports.handleProxzeKycHeadlessEvent)(event, bg));
29
+ };
30
+ exports.registerProxzeKycHeadlessTask = registerProxzeKycHeadlessTask;
31
+ /** The SDK's share of a headless event, for apps with their own headless task. */
32
+ const handleProxzeKycHeadlessEvent = async (event, bg = loadPlugin()) => {
33
+ if ((event === null || event === void 0 ? void 0 : event.name) !== 'heartbeat')
34
+ return;
35
+ try {
36
+ // Stored and synced by the library's native HTTP service.
37
+ await (0, backgroundGeolocationAdapter_1.sampleForNight)(bg);
38
+ }
39
+ catch {
40
+ /* no fix this time; the next heartbeat tries again */
41
+ }
42
+ };
43
+ exports.handleProxzeKycHeadlessEvent = handleProxzeKycHeadlessEvent;
44
+ const loadPlugin = () => {
45
+ var _a;
46
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
47
+ const mod = require('react-native-background-geolocation');
48
+ return (_a = mod === null || mod === void 0 ? void 0 : mod.default) !== null && _a !== void 0 ? _a : mod;
49
+ };
package/dist/hooks.d.ts CHANGED
@@ -15,7 +15,7 @@ export interface UseProxzeKycResult {
15
15
  *
16
16
  * ```tsx
17
17
  * const { session, state, kyc } = useProxzeKyc({
18
- * baseUrl: 'https://api.proxze.com',
18
+ * baseUrl: KYC_API_BASE_URL,
19
19
  * sessionToken,
20
20
  * });
21
21
  *
package/dist/hooks.js CHANGED
@@ -8,7 +8,7 @@ const session_1 = require("./session");
8
8
  *
9
9
  * ```tsx
10
10
  * const { session, state, kyc } = useProxzeKyc({
11
- * baseUrl: 'https://api.proxze.com',
11
+ * baseUrl: KYC_API_BASE_URL,
12
12
  * sessionToken,
13
13
  * });
14
14
  *
@@ -52,7 +52,11 @@ function useProxzeKyc(options) {
52
52
  });
53
53
  return () => {
54
54
  cancelled = true;
55
- void kyc.stopTracking();
55
+ // Detach only. Stopping here removed the fence and stopped the location
56
+ // library whenever the customer left this screen, so tracking only ever
57
+ // ran while the screen stayed open. Tracking ends when the verification
58
+ // closes (bootstrap sees it) or the app calls `kyc.stopTracking()`.
59
+ kyc.detach();
56
60
  };
57
61
  }, [kyc]);
58
62
  return { session, state, loading, error, kyc };
package/dist/index.d.ts CHANGED
@@ -8,8 +8,12 @@ export { OfflineEventQueue } from './queue';
8
8
  export type { QueueEventInput } from './queue';
9
9
  export { memoryStorage, defaultStorage } from './storage';
10
10
  export type { StorageAdapter } from './storage';
11
- export type { LocationAdapter, AdapterLocationEvent, LocationEventListener, PermissionState, PermissionGrade, } from './location/adapter';
11
+ export type { LocationAdapter, AdapterLocationEvent, LocationEventListener, PermissionState, PermissionGrade, NativeDeliveryTarget, NativeDeliveryStatus, } from './location/adapter';
12
12
  export { BackgroundGeolocationAdapter } from './location/backgroundGeolocationAdapter';
13
- export { buildWindow, nightWindowFor, isWithinNightWindow, isInMorningCheckSlot, msUntilNextSample, WAT_OFFSET_MINUTES, PING_INTERVAL_MINUTES, } from './nightWindow';
13
+ export type { BackgroundGeolocationAdapterOptions } from './location/backgroundGeolocationAdapter';
14
+ export { registerProxzeKycHeadlessTask, handleProxzeKycHeadlessEvent } from './headless';
15
+ export { restoreProxzeKycTracking } from './restore';
16
+ export { SDK_GEOFENCE_IDENTIFIER } from './constants';
17
+ export { buildWindow, nightWindowFor, isWithinNightWindow, isInMorningCheckSlot, isSamplingTime, msUntilNextSample, WAT_OFFSET_MINUTES, PING_INTERVAL_MINUTES, } from './nightWindow';
14
18
  export type { NightWindow } from './nightWindow';
15
19
  export * from './types';
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.PING_INTERVAL_MINUTES = exports.WAT_OFFSET_MINUTES = exports.msUntilNextSample = exports.isInMorningCheckSlot = exports.isWithinNightWindow = exports.nightWindowFor = exports.buildWindow = exports.BackgroundGeolocationAdapter = exports.defaultStorage = exports.memoryStorage = exports.OfflineEventQueue = exports.useProxzeKyc = exports.ProxzeKycSession = exports.ProxzeKycError = exports.ProxzeKycClient = void 0;
17
+ exports.PING_INTERVAL_MINUTES = exports.WAT_OFFSET_MINUTES = exports.msUntilNextSample = exports.isSamplingTime = exports.isInMorningCheckSlot = exports.isWithinNightWindow = exports.nightWindowFor = exports.buildWindow = exports.SDK_GEOFENCE_IDENTIFIER = exports.restoreProxzeKycTracking = exports.handleProxzeKycHeadlessEvent = exports.registerProxzeKycHeadlessTask = exports.BackgroundGeolocationAdapter = exports.defaultStorage = exports.memoryStorage = exports.OfflineEventQueue = exports.useProxzeKyc = exports.ProxzeKycSession = exports.ProxzeKycError = exports.ProxzeKycClient = void 0;
18
18
  var client_1 = require("./client");
19
19
  Object.defineProperty(exports, "ProxzeKycClient", { enumerable: true, get: function () { return client_1.ProxzeKycClient; } });
20
20
  Object.defineProperty(exports, "ProxzeKycError", { enumerable: true, get: function () { return client_1.ProxzeKycError; } });
@@ -29,11 +29,19 @@ Object.defineProperty(exports, "memoryStorage", { enumerable: true, get: functio
29
29
  Object.defineProperty(exports, "defaultStorage", { enumerable: true, get: function () { return storage_1.defaultStorage; } });
30
30
  var backgroundGeolocationAdapter_1 = require("./location/backgroundGeolocationAdapter");
31
31
  Object.defineProperty(exports, "BackgroundGeolocationAdapter", { enumerable: true, get: function () { return backgroundGeolocationAdapter_1.BackgroundGeolocationAdapter; } });
32
+ var headless_1 = require("./headless");
33
+ Object.defineProperty(exports, "registerProxzeKycHeadlessTask", { enumerable: true, get: function () { return headless_1.registerProxzeKycHeadlessTask; } });
34
+ Object.defineProperty(exports, "handleProxzeKycHeadlessEvent", { enumerable: true, get: function () { return headless_1.handleProxzeKycHeadlessEvent; } });
35
+ var restore_1 = require("./restore");
36
+ Object.defineProperty(exports, "restoreProxzeKycTracking", { enumerable: true, get: function () { return restore_1.restoreProxzeKycTracking; } });
37
+ var constants_1 = require("./constants");
38
+ Object.defineProperty(exports, "SDK_GEOFENCE_IDENTIFIER", { enumerable: true, get: function () { return constants_1.SDK_GEOFENCE_IDENTIFIER; } });
32
39
  var nightWindow_1 = require("./nightWindow");
33
40
  Object.defineProperty(exports, "buildWindow", { enumerable: true, get: function () { return nightWindow_1.buildWindow; } });
34
41
  Object.defineProperty(exports, "nightWindowFor", { enumerable: true, get: function () { return nightWindow_1.nightWindowFor; } });
35
42
  Object.defineProperty(exports, "isWithinNightWindow", { enumerable: true, get: function () { return nightWindow_1.isWithinNightWindow; } });
36
43
  Object.defineProperty(exports, "isInMorningCheckSlot", { enumerable: true, get: function () { return nightWindow_1.isInMorningCheckSlot; } });
44
+ Object.defineProperty(exports, "isSamplingTime", { enumerable: true, get: function () { return nightWindow_1.isSamplingTime; } });
37
45
  Object.defineProperty(exports, "msUntilNextSample", { enumerable: true, get: function () { return nightWindow_1.msUntilNextSample; } });
38
46
  Object.defineProperty(exports, "WAT_OFFSET_MINUTES", { enumerable: true, get: function () { return nightWindow_1.WAT_OFFSET_MINUTES; } });
39
47
  Object.defineProperty(exports, "PING_INTERVAL_MINUTES", { enumerable: true, get: function () { return nightWindow_1.PING_INTERVAL_MINUTES; } });
@@ -22,6 +22,26 @@ export interface PermissionState {
22
22
  */
23
23
  precise: boolean;
24
24
  }
25
+ /**
26
+ * Where an adapter that can talk HTTP on its own should send location events.
27
+ * The body format is the adapter's business; the server endpoint at `url`
28
+ * must understand it (`/v2/sdk/locations` reads react-native-background-
29
+ * geolocation's native format).
30
+ */
31
+ export interface NativeDeliveryTarget {
32
+ url: string;
33
+ headers: Record<string, string>;
34
+ /** Merged into every request body: platform, SDK version, device id. */
35
+ params: Record<string, string>;
36
+ }
37
+ /** What native delivery has been up to, for a support/diagnostics screen. */
38
+ export interface NativeDeliveryStatus {
39
+ /** Records captured on the device and not yet acknowledged by the server. */
40
+ pending: number | null;
41
+ /** HTTP status of the most recent sync this process saw (401 = session closed or wrong environment). */
42
+ lastStatus: number | null;
43
+ lastAt: string | null;
44
+ }
25
45
  /**
26
46
  * The seam between the SDK's verification logic and whatever location stack
27
47
  * the host app ships.
@@ -54,4 +74,19 @@ export interface LocationAdapter {
54
74
  getCurrentPosition(): Promise<AdapterLocationEvent>;
55
75
  /** Subscribe to geofence transitions and heartbeats. Returns unsubscribe. */
56
76
  onEvent(listener: LocationEventListener): () => void;
77
+ /**
78
+ * Optional: deliver events to the server natively, without JavaScript.
79
+ *
80
+ * An adapter that implements this sends its own events (from a killed app,
81
+ * after a reboot) and the session stops queueing them through JavaScript,
82
+ * which would deliver every event twice. Adapters without it keep using the
83
+ * SDK's JavaScript queue, which only runs while the app is alive.
84
+ */
85
+ configureNativeDelivery?(target: NativeDeliveryTarget): Promise<void>;
86
+ /** Optional: stop native delivery and discard anything not yet sent. */
87
+ clearNativeDelivery?(): Promise<void>;
88
+ /** Optional: native delivery health for `diagnostics()`. */
89
+ nativeDeliveryStatus?(): Promise<NativeDeliveryStatus>;
90
+ /** Optional: whether the OS currently holds the verification geofence. */
91
+ isGeofenceRegistered?(): Promise<boolean>;
57
92
  }
@@ -1,41 +1,112 @@
1
1
  import { GeofenceConfig } from '../types';
2
- import { AdapterLocationEvent, LocationAdapter, LocationEventListener, PermissionState } from './adapter';
2
+ import { AdapterLocationEvent, LocationAdapter, LocationEventListener, NativeDeliveryStatus, NativeDeliveryTarget, PermissionState } from './adapter';
3
+ export interface BackgroundGeolocationAdapterOptions {
4
+ /** Plays a sound and logs verbosely on every event. Development builds only. */
5
+ debug?: boolean;
6
+ /**
7
+ * iOS: keep the app from being suspended while stationary, which is the
8
+ * only way iOS fires the 30-minute heartbeat in the background. Without it
9
+ * an iPhone sends nothing overnight for someone who stays home. Defaults to
10
+ * true; it costs battery for the length of the verification window.
11
+ */
12
+ iosPreventSuspend?: boolean;
13
+ /**
14
+ * Android 11+: the dialog that sends the customer to settings to pick
15
+ * "Allow all the time". The geofence needs background location, which the
16
+ * system permission prompt never offers on 11+.
17
+ */
18
+ backgroundPermissionRationale?: {
19
+ title: string;
20
+ message: string;
21
+ positiveAction: string;
22
+ negativeAction: string;
23
+ };
24
+ /**
25
+ * @deprecated Has no effect. The library reads its license from the
26
+ * AndroidManifest (`com.transistorsoft.locationmanager.license`); release
27
+ * builds without one do not track at all.
28
+ */
29
+ license?: string;
30
+ }
31
+ /**
32
+ * Take a fix that the library stores and syncs itself, if now is a time a
33
+ * fix can count toward a night. Shared by the JS heartbeat listener and the
34
+ * Android headless task, which is what runs once the app has been killed.
35
+ */
36
+ export declare const sampleForNight: (bg: any, now?: Date) => Promise<any | null>;
3
37
  /**
4
38
  * Default adapter over `react-native-background-geolocation` (Transistorsoft).
5
39
  *
6
40
  * Chosen because it is the one battle-tested way to get what this product
7
41
  * needs on both platforms: geofence enter/exit that survives app termination,
8
- * a heartbeat that still fires under Doze, and mock-location flags. On Android
9
- * it rides Google Play Services (fused location + Geofencing API) — the same
10
- * Google location stack the rest of the Proxze platform uses; on iOS it rides
11
- * CoreLocation region monitoring, which is why the "arrived and stayed" night
12
- * strategy exists at all: iOS will not deliver 30-minute background pings, and
13
- * the service's HYBRID evaluator already accounts for that.
42
+ * a heartbeat that still fires under Doze, mock-location flags, and its own
43
+ * native HTTP sync. On Android it rides Google Play Services (fused location
44
+ * + Geofencing API); on iOS, CoreLocation region monitoring.
45
+ *
46
+ * Delivery is native. The library stores every geofence transition and every
47
+ * heartbeat fix in its own database and posts them to `/v2/sdk/locations`
48
+ * itself, so events reach the server while the app is backgrounded, killed or
49
+ * rebooting. Before this the SDK's JavaScript queue carried them, and that
50
+ * only runs while the app is open: most nights arrived late or never.
51
+ *
52
+ * Tracking is geofences-only. The library never records the customer's
53
+ * movements; the only fixes are the heartbeat samples taken inside the night
54
+ * window and the morning-check slot (`isSamplingTime`).
14
55
  *
15
56
  * The library is an optional peer dependency — constructing this adapter
16
57
  * without it installed throws with install instructions.
17
58
  */
18
59
  export declare class BackgroundGeolocationAdapter implements LocationAdapter {
19
60
  private readonly bg;
61
+ private readonly options;
20
62
  private listeners;
21
63
  private subscriptions;
22
64
  private started;
23
- constructor(options?: {
24
- license?: string;
25
- debug?: boolean;
26
- });
27
- private readonly debug;
65
+ private delivery?;
66
+ constructor(options?: BackgroundGeolocationAdapterOptions);
28
67
  requestPermissions(): Promise<PermissionState>;
29
68
  checkPermissions(): Promise<PermissionState>;
30
69
  private toPermissionState;
70
+ /**
71
+ * Add the verification fence, unless the OS already holds it unchanged.
72
+ * Re-adding fires a fresh initial ENTER every time the app opens at home,
73
+ * which is noise, so an identical fence is left alone.
74
+ */
31
75
  registerGeofence(fence: GeofenceConfig): Promise<void>;
32
76
  clearGeofence(): Promise<void>;
77
+ isGeofenceRegistered(): Promise<boolean>;
33
78
  start(): Promise<void>;
79
+ /**
80
+ * Stop the plugin entirely. Unconditional: the plugin is process-wide, and
81
+ * a verification that ended while the app was closed is stopped by an
82
+ * adapter instance that never called `start()` itself.
83
+ */
34
84
  stop(): Promise<void>;
85
+ /**
86
+ * A one-shot fix for the foreground scheduler. With native delivery the
87
+ * library stores it and syncs it itself; without, it is returned for the
88
+ * JavaScript queue and not stored.
89
+ */
35
90
  getCurrentPosition(): Promise<AdapterLocationEvent>;
36
91
  onEvent(listener: LocationEventListener): () => void;
37
- private readyPromise;
92
+ configureNativeDelivery(target: NativeDeliveryTarget): Promise<void>;
93
+ clearNativeDelivery(): Promise<void>;
94
+ nativeDeliveryStatus(): Promise<NativeDeliveryStatus>;
95
+ /**
96
+ * The library config. `ready()` is called with `reset: false` so a relaunch
97
+ * never wipes the URL and token a previous launch set (Android keeps
98
+ * syncing after a reboot with no JavaScript, from the persisted config);
99
+ * `setConfig` then applies this launch's values on top.
100
+ */
101
+ private config;
38
102
  private ready;
103
+ private currentGeofence;
104
+ private unsubscribeAll;
39
105
  private fromLocation;
40
- private emit;
106
+ /** The library's location record as an adapter event. */
107
+ private static toEvent;
108
+ /** Deliver to this instance's listeners. Not private: the heartbeat fans out to every instance. */
109
+ emit(event: AdapterLocationEvent): void;
41
110
  }
111
+ /** Test hook: forget the per-process ready state. */
112
+ export declare const __resetBackgroundGeolocationForTests: () => void;