@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/dist/session.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ProxzeKycClient } from './client';
2
2
  import { StorageAdapter } from './storage';
3
- import { LocationAdapter, PermissionState } from './location/adapter';
3
+ import { LocationAdapter, NativeDeliveryStatus, PermissionState } from './location/adapter';
4
4
  import { BillUploadResponse, RestartResponse, RNFile, SdkSession, UtilityDocumentType, VideoMeta, VideoUploadResponse } from './types';
5
5
  export type KycTrackingState = 'idle' | 'awaiting_consent' | 'awaiting_permissions' | 'awaiting_address_pin' | 'tracking' | 'completed' | 'stopped';
6
6
  export interface KycSessionEvents {
@@ -9,13 +9,13 @@ export interface KycSessionEvents {
9
9
  onError?: (error: Error) => void;
10
10
  }
11
11
  export interface ProxzeKycSessionOptions {
12
- /** e.g. `https://api.proxze.com`. */
12
+ /** The KYC API host the verification was initiated on (no trailing slash, no `/v2`). */
13
13
  baseUrl: string;
14
14
  /** From the bank backend's `POST /v2/kyc/initiate` response. */
15
15
  sessionToken: string;
16
16
  /** Location stack. Defaults to the background-geolocation adapter. */
17
17
  adapter?: LocationAdapter;
18
- /** Queue persistence. Defaults to AsyncStorage when installed. */
18
+ /** Queue and tracking-record persistence. Defaults to AsyncStorage when installed. */
19
19
  storage?: StorageAdapter;
20
20
  deviceId?: string;
21
21
  events?: KycSessionEvents;
@@ -28,27 +28,44 @@ export interface ProxzeKycSessionOptions {
28
28
  *
29
29
  * Night tracking is dual-mode, matching the service's HYBRID evaluator:
30
30
  * geofence enter/exit transitions arrive from the OS whenever they happen,
31
- * and a scheduler requests position samples on the 30-minute marks inside
32
- * the 12AM–5AM window plus one morning check after it closes. Whichever
33
- * signals survive the device's battery policies, the server can score.
31
+ * and a 30-minute heartbeat takes position samples inside the 12AM–5AM window
32
+ * plus the morning-check slot after it.
33
+ *
34
+ * Tracking belongs to the verification, not to a screen. It starts once, keeps
35
+ * running natively while the app is closed, resumes by itself on the next
36
+ * launch (`bootstrap`), and ends only when the verification closes or
37
+ * `stopTracking()` is called. Unmounting a screen calls `detach()`, which drops
38
+ * this object's timers and listeners and leaves the native side alone.
34
39
  */
35
40
  export declare class ProxzeKycSession {
36
41
  readonly client: ProxzeKycClient;
37
42
  private readonly storage;
38
43
  private readonly events;
39
44
  private readonly deviceId?;
45
+ private readonly baseUrl;
46
+ private readonly sessionToken;
40
47
  private adapter?;
41
48
  private adapterFactory?;
42
49
  private queue?;
43
50
  private session?;
44
51
  private state;
52
+ /** True when the adapter delivers events itself and the JS queue stays idle. */
53
+ private nativeDelivery;
45
54
  private sampleTimer?;
46
55
  private flushTimer?;
56
+ private lastStatusRefresh;
47
57
  private unsubscribe?;
48
58
  constructor(options: ProxzeKycSessionOptions);
49
59
  getState(): KycTrackingState;
50
60
  getSession(): SdkSession | undefined;
51
- /** Fetch server-side state and derive the local step. */
61
+ /**
62
+ * Fetch server-side state and derive the local step.
63
+ *
64
+ * If this device was already tracking this verification, tracking resumes
65
+ * here without prompting: the customer granted permission once, and asking
66
+ * again on every app open is how verifications quietly stopped tracking.
67
+ * A closed verification stops tracking for good.
68
+ */
52
69
  bootstrap(): Promise<SdkSession>;
53
70
  /** Record NDPR consent. Must precede any location work. */
54
71
  grantConsent(consentVersion: string): Promise<void>;
@@ -72,7 +89,18 @@ export declare class ProxzeKycSession {
72
89
  * signals still feed the server's hybrid evaluator.
73
90
  */
74
91
  startTracking(): Promise<PermissionState>;
75
- /** Stop monitoring and clear the fence (verification finished or abandoned). */
92
+ /**
93
+ * Let go of this object's timers and listeners without touching the native
94
+ * side: the fence, the library and native delivery keep running. This is
95
+ * what unmounting a screen should do (and what `useProxzeKyc` does).
96
+ */
97
+ detach(): void;
98
+ /**
99
+ * End tracking for good: remove the fence, stop the location library,
100
+ * discard anything not yet delivered and forget the verification. Call it
101
+ * when the verification is finished or abandoned — never on unmount, which
102
+ * is what `detach()` is for.
103
+ */
76
104
  stopTracking(): Promise<void>;
77
105
  /** NDPR — stops collection immediately, server-side and locally. */
78
106
  withdrawConsent(): Promise<void>;
@@ -83,18 +111,31 @@ export declare class ProxzeKycSession {
83
111
  refresh(): Promise<SdkSession>;
84
112
  /**
85
113
  * Tracking health for a status screen or support tooling: what the OS is
86
- * actually letting us do, and whether events are reaching the server.
114
+ * actually letting us do, whether the fence is registered, and whether
115
+ * events are reaching the server. `nativeDelivery.lastStatus` of 401 means
116
+ * the session is closed, or the app points at a different environment from
117
+ * the one the verification was started in.
87
118
  */
88
119
  diagnostics(): Promise<{
89
120
  state: KycTrackingState;
90
121
  permission: PermissionState | null;
122
+ geofenceRegistered: boolean | null;
91
123
  queuedEvents: number;
124
+ nativeDelivery: NativeDeliveryStatus | null;
92
125
  sessionStatus: string | null;
93
126
  }>;
94
127
  private resolveAdapter;
128
+ /** Whether storage says this device is tracking under this session token. */
129
+ private isTrackingThisToken;
130
+ /** Pick tracking back up after a relaunch, without a permission prompt. */
131
+ private resume;
132
+ /** Arm delivery, the fence, listeners and timers. Safe to call again. */
133
+ private engage;
95
134
  private handleEvent;
96
135
  private scheduleNextSample;
136
+ private tick;
97
137
  private flushQueue;
138
+ private stopIfClosed;
98
139
  private setState;
99
140
  private emitError;
100
141
  }
package/dist/session.js CHANGED
@@ -5,11 +5,11 @@ const client_1 = require("./client");
5
5
  const queue_1 = require("./queue");
6
6
  const storage_1 = require("./storage");
7
7
  const nightWindow_1 = require("./nightWindow");
8
- // Read from the manifest so the version reported to the server never drifts
9
- // from the published one (resolves to the package root from both src/ and dist/).
10
- // eslint-disable-next-line @typescript-eslint/no-var-requires
11
- const SDK_VERSION = require('../package.json').version;
8
+ const tracking_1 = require("./tracking");
12
9
  const FLUSH_INTERVAL_MS = 60000;
10
+ /** With native delivery there is nothing to flush; just watch for the decision. */
11
+ const STATUS_REFRESH_MS = 5 * 60000;
12
+ const ACTIVE_STATUSES = ['initiated', 'in_progress'];
13
13
  /**
14
14
  * Orchestrates one verification on the device:
15
15
  *
@@ -18,14 +18,24 @@ const FLUSH_INTERVAL_MS = 60000;
18
18
  *
19
19
  * Night tracking is dual-mode, matching the service's HYBRID evaluator:
20
20
  * geofence enter/exit transitions arrive from the OS whenever they happen,
21
- * and a scheduler requests position samples on the 30-minute marks inside
22
- * the 12AM–5AM window plus one morning check after it closes. Whichever
23
- * signals survive the device's battery policies, the server can score.
21
+ * and a 30-minute heartbeat takes position samples inside the 12AM–5AM window
22
+ * plus the morning-check slot after it.
23
+ *
24
+ * Tracking belongs to the verification, not to a screen. It starts once, keeps
25
+ * running natively while the app is closed, resumes by itself on the next
26
+ * launch (`bootstrap`), and ends only when the verification closes or
27
+ * `stopTracking()` is called. Unmounting a screen calls `detach()`, which drops
28
+ * this object's timers and listeners and leaves the native side alone.
24
29
  */
25
30
  class ProxzeKycSession {
26
31
  constructor(options) {
27
32
  var _a, _b;
28
33
  this.state = 'idle';
34
+ /** True when the adapter delivers events itself and the JS queue stays idle. */
35
+ this.nativeDelivery = false;
36
+ this.lastStatusRefresh = 0;
37
+ this.baseUrl = options.baseUrl;
38
+ this.sessionToken = options.sessionToken;
29
39
  this.client = new client_1.ProxzeKycClient({
30
40
  baseUrl: options.baseUrl,
31
41
  sessionToken: options.sessionToken,
@@ -53,18 +63,48 @@ class ProxzeKycSession {
53
63
  getSession() {
54
64
  return this.session;
55
65
  }
56
- /** Fetch server-side state and derive the local step. */
66
+ /**
67
+ * Fetch server-side state and derive the local step.
68
+ *
69
+ * If this device was already tracking this verification, tracking resumes
70
+ * here without prompting: the customer granted permission once, and asking
71
+ * again on every app open is how verifications quietly stopped tracking.
72
+ * A closed verification stops tracking for good.
73
+ */
57
74
  async bootstrap() {
58
75
  var _a, _b;
59
- const session = await this.client.getSession();
76
+ let session;
77
+ try {
78
+ session = await this.client.getSession();
79
+ }
80
+ catch (err) {
81
+ // A dead token (decision issued, window expired) can never be reported
82
+ // against again, so a device tracking under it should stop.
83
+ if (err instanceof client_1.ProxzeKycError && err.isSessionClosed && (await this.isTrackingThisToken())) {
84
+ await this.stopTracking();
85
+ this.setState('completed');
86
+ }
87
+ throw err;
88
+ }
60
89
  this.session = session;
61
90
  (_b = (_a = this.events).onSessionUpdate) === null || _b === void 0 ? void 0 : _b.call(_a, session);
62
- if (session.consentRequired)
91
+ if (!ACTIVE_STATUSES.includes(session.status)) {
92
+ if (await this.isTrackingThisToken())
93
+ await this.stopTracking();
94
+ this.setState('completed');
95
+ }
96
+ else if (session.consentRequired) {
63
97
  this.setState('awaiting_consent');
64
- else if (session.addressConfirmationRequired)
98
+ }
99
+ else if (session.addressConfirmationRequired) {
65
100
  this.setState('awaiting_address_pin');
66
- else
101
+ }
102
+ else if (await this.isTrackingThisToken()) {
103
+ await this.resume();
104
+ }
105
+ else {
67
106
  this.setState('awaiting_permissions');
107
+ }
68
108
  return session;
69
109
  }
70
110
  /** Record NDPR consent. Must precede any location work. */
@@ -115,20 +155,15 @@ class ProxzeKycSession {
115
155
  this.emitError(new Error('Location permission denied'));
116
156
  return permission;
117
157
  }
118
- this.queue = new queue_1.OfflineEventQueue(this.storage, session.kycId);
119
- await adapter.registerGeofence(session.geofence);
120
- await this.client.acknowledgeGeofence().catch(() => undefined);
121
- this.unsubscribe = adapter.onEvent((event) => {
122
- void this.handleEvent(event);
123
- });
124
- await adapter.start();
125
- this.scheduleNextSample();
126
- this.flushTimer = setInterval(() => void this.flushQueue(), FLUSH_INTERVAL_MS);
127
- this.setState('tracking');
158
+ await this.engage(adapter, session);
128
159
  return permission;
129
160
  }
130
- /** Stop monitoring and clear the fence (verification finished or abandoned). */
131
- async stopTracking() {
161
+ /**
162
+ * Let go of this object's timers and listeners without touching the native
163
+ * side: the fence, the library and native delivery keep running. This is
164
+ * what unmounting a screen should do (and what `useProxzeKyc` does).
165
+ */
166
+ detach() {
132
167
  var _a;
133
168
  if (this.sampleTimer)
134
169
  clearTimeout(this.sampleTimer);
@@ -138,10 +173,30 @@ class ProxzeKycSession {
138
173
  this.flushTimer = undefined;
139
174
  (_a = this.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
140
175
  this.unsubscribe = undefined;
141
- if (this.adapter) {
142
- await this.adapter.clearGeofence().catch(() => undefined);
143
- await this.adapter.stop().catch(() => undefined);
176
+ }
177
+ /**
178
+ * End tracking for good: remove the fence, stop the location library,
179
+ * discard anything not yet delivered and forget the verification. Call it
180
+ * when the verification is finished or abandoned — never on unmount, which
181
+ * is what `detach()` is for.
182
+ */
183
+ async stopTracking() {
184
+ var _a;
185
+ this.detach();
186
+ let adapter;
187
+ try {
188
+ adapter = this.resolveAdapter();
189
+ }
190
+ catch {
191
+ adapter = undefined; // no location stack installed: nothing native to stop
192
+ }
193
+ if (adapter) {
194
+ await adapter.clearGeofence().catch(() => undefined);
195
+ await ((_a = adapter.clearNativeDelivery) === null || _a === void 0 ? void 0 : _a.call(adapter).catch(() => undefined));
196
+ await adapter.stop().catch(() => undefined);
144
197
  }
198
+ await (0, tracking_1.clearTrackingRecord)(this.storage);
199
+ this.nativeDelivery = false;
145
200
  if (this.state === 'tracking')
146
201
  this.setState('stopped');
147
202
  }
@@ -175,13 +230,21 @@ class ProxzeKycSession {
175
230
  }
176
231
  /**
177
232
  * Tracking health for a status screen or support tooling: what the OS is
178
- * actually letting us do, and whether events are reaching the server.
233
+ * actually letting us do, whether the fence is registered, and whether
234
+ * events are reaching the server. `nativeDelivery.lastStatus` of 401 means
235
+ * the session is closed, or the app points at a different environment from
236
+ * the one the verification was started in.
179
237
  */
180
238
  async diagnostics() {
181
- var _a, _b;
239
+ var _a, _b, _c, _d, _e, _f;
182
240
  let permission = null;
241
+ let geofenceRegistered = null;
242
+ let nativeDelivery = null;
183
243
  try {
184
- permission = await this.resolveAdapter().checkPermissions();
244
+ const adapter = this.resolveAdapter();
245
+ permission = await adapter.checkPermissions();
246
+ geofenceRegistered = (_b = (await ((_a = adapter.isGeofenceRegistered) === null || _a === void 0 ? void 0 : _a.call(adapter)))) !== null && _b !== void 0 ? _b : null;
247
+ nativeDelivery = (_d = (await ((_c = adapter.nativeDeliveryStatus) === null || _c === void 0 ? void 0 : _c.call(adapter)))) !== null && _d !== void 0 ? _d : null;
185
248
  }
186
249
  catch {
187
250
  /* adapter not available yet */
@@ -189,8 +252,10 @@ class ProxzeKycSession {
189
252
  return {
190
253
  state: this.state,
191
254
  permission,
255
+ geofenceRegistered,
192
256
  queuedEvents: this.queue ? await this.queue.size() : 0,
193
- sessionStatus: (_b = (_a = this.session) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : null,
257
+ nativeDelivery,
258
+ sessionStatus: (_f = (_e = this.session) === null || _e === void 0 ? void 0 : _e.status) !== null && _f !== void 0 ? _f : null,
194
259
  };
195
260
  }
196
261
  // ---------------------------------------------------------------------------
@@ -199,8 +264,60 @@ class ProxzeKycSession {
199
264
  this.adapter = this.adapterFactory();
200
265
  return this.adapter;
201
266
  }
267
+ /** Whether storage says this device is tracking under this session token. */
268
+ async isTrackingThisToken() {
269
+ const record = await (0, tracking_1.readTrackingRecord)(this.storage);
270
+ return (record === null || record === void 0 ? void 0 : record.sessionToken) === this.sessionToken;
271
+ }
272
+ /** Pick tracking back up after a relaunch, without a permission prompt. */
273
+ async resume() {
274
+ const session = this.session;
275
+ if (!session.geofence) {
276
+ this.setState('awaiting_permissions');
277
+ return;
278
+ }
279
+ const adapter = this.resolveAdapter();
280
+ const permission = await adapter.checkPermissions().catch(() => null);
281
+ if (!permission || permission.grade === 'denied') {
282
+ // Revoked in settings since: the app has to ask again.
283
+ this.setState('awaiting_permissions');
284
+ return;
285
+ }
286
+ await this.engage(adapter, session);
287
+ }
288
+ /** Arm delivery, the fence, listeners and timers. Safe to call again. */
289
+ async engage(adapter, session) {
290
+ this.detach();
291
+ this.queue = new queue_1.OfflineEventQueue(this.storage, session.kycId);
292
+ const record = {
293
+ kycId: session.kycId,
294
+ baseUrl: this.baseUrl,
295
+ sessionToken: this.sessionToken,
296
+ deviceId: this.deviceId,
297
+ startedAt: new Date().toISOString(),
298
+ };
299
+ this.nativeDelivery = typeof adapter.configureNativeDelivery === 'function';
300
+ if (this.nativeDelivery) {
301
+ await adapter.configureNativeDelivery((0, tracking_1.nativeDeliveryTarget)(record));
302
+ }
303
+ await adapter.registerGeofence(session.geofence);
304
+ await this.client.acknowledgeGeofence().catch(() => undefined);
305
+ this.unsubscribe = adapter.onEvent((event) => {
306
+ void this.handleEvent(event);
307
+ });
308
+ await adapter.start();
309
+ // With native delivery the adapter's heartbeat samples, foreground or not.
310
+ // A second sampler here would store two fixes per half hour.
311
+ if (!this.nativeDelivery)
312
+ this.scheduleNextSample();
313
+ this.flushTimer = setInterval(() => void this.tick(), FLUSH_INTERVAL_MS);
314
+ await (0, tracking_1.writeTrackingRecord)(this.storage, record);
315
+ this.setState('tracking');
316
+ }
202
317
  async handleEvent(event) {
203
- if (!this.queue)
318
+ // The adapter already stored this event for its own delivery; queueing it
319
+ // too would deliver it twice, and a ping counted twice could fake a night.
320
+ if (this.nativeDelivery || !this.queue)
204
321
  return;
205
322
  // Re-label a generic sample by when it happened: inside the window it is a
206
323
  // ping the evaluator counts; in the grace slot it is the morning check.
@@ -218,8 +335,7 @@ class ProxzeKycSession {
218
335
  const delay = Math.max((0, nightWindow_1.msUntilNextSample)(), 15000);
219
336
  this.sampleTimer = setTimeout(async () => {
220
337
  try {
221
- if (this.adapter &&
222
- ((0, nightWindow_1.isWithinNightWindow)(new Date()) || (0, nightWindow_1.isInMorningCheckSlot)(new Date()))) {
338
+ if (this.adapter && (0, nightWindow_1.isSamplingTime)(new Date())) {
223
339
  const position = await this.adapter.getCurrentPosition();
224
340
  await this.handleEvent(position);
225
341
  }
@@ -233,23 +349,37 @@ class ProxzeKycSession {
233
349
  }
234
350
  }, delay);
235
351
  }
352
+ async tick() {
353
+ if (!this.nativeDelivery) {
354
+ await this.flushQueue();
355
+ return;
356
+ }
357
+ if (Date.now() - this.lastStatusRefresh < STATUS_REFRESH_MS)
358
+ return;
359
+ this.lastStatusRefresh = Date.now();
360
+ try {
361
+ await this.refresh();
362
+ await this.stopIfClosed();
363
+ }
364
+ catch (err) {
365
+ if (err instanceof client_1.ProxzeKycError && err.isSessionClosed) {
366
+ await this.stopTracking();
367
+ this.setState('completed');
368
+ }
369
+ }
370
+ }
236
371
  async flushQueue() {
237
- var _a;
238
372
  if (!this.queue)
239
373
  return;
240
374
  try {
241
375
  const result = await this.queue.flush(this.client, {
242
- platform: detectPlatform(),
243
- sdkVersion: SDK_VERSION,
376
+ platform: (0, tracking_1.detectPlatform)(),
377
+ sdkVersion: tracking_1.SDK_VERSION,
244
378
  deviceId: this.deviceId,
245
379
  });
246
380
  if (result.sent > 0)
247
381
  await this.refresh().catch(() => undefined);
248
- const status = (_a = this.session) === null || _a === void 0 ? void 0 : _a.status;
249
- if (status && status !== 'initiated' && status !== 'in_progress') {
250
- await this.stopTracking();
251
- this.setState('completed');
252
- }
382
+ await this.stopIfClosed();
253
383
  }
254
384
  catch (err) {
255
385
  if (err instanceof client_1.ProxzeKycError && err.isSessionClosed) {
@@ -262,6 +392,14 @@ class ProxzeKycSession {
262
392
  this.emitError(err);
263
393
  }
264
394
  }
395
+ async stopIfClosed() {
396
+ var _a;
397
+ const status = (_a = this.session) === null || _a === void 0 ? void 0 : _a.status;
398
+ if (status && !ACTIVE_STATUSES.includes(status)) {
399
+ await this.stopTracking();
400
+ this.setState('completed');
401
+ }
402
+ }
265
403
  setState(state) {
266
404
  var _a, _b;
267
405
  if (this.state === state)
@@ -275,15 +413,3 @@ class ProxzeKycSession {
275
413
  }
276
414
  }
277
415
  exports.ProxzeKycSession = ProxzeKycSession;
278
- const detectPlatform = () => {
279
- try {
280
- // eslint-disable-next-line @typescript-eslint/no-var-requires
281
- const { Platform } = require('react-native');
282
- return (Platform === null || Platform === void 0 ? void 0 : Platform.OS) === 'ios' || (Platform === null || Platform === void 0 ? void 0 : Platform.OS) === 'android'
283
- ? Platform.OS
284
- : undefined;
285
- }
286
- catch {
287
- return undefined;
288
- }
289
- };
@@ -0,0 +1,29 @@
1
+ import { StorageAdapter } from './storage';
2
+ import { NativeDeliveryTarget } from './location/adapter';
3
+ export declare const SDK_VERSION: string;
4
+ /**
5
+ * The verification this device is tracking, kept so tracking resumes after a
6
+ * relaunch without the customer going through the permission screen again,
7
+ * and so `restoreProxzeKycTracking` can re-arm native delivery at launch.
8
+ *
9
+ * Holds the session token. That token is scoped to one verification and
10
+ * dies with it, and the location library already keeps it in its own config
11
+ * for native sync, so this adds no new exposure.
12
+ */
13
+ export interface TrackingRecord {
14
+ kycId: string;
15
+ baseUrl: string;
16
+ sessionToken: string;
17
+ deviceId?: string;
18
+ startedAt: string;
19
+ }
20
+ export declare const readTrackingRecord: (storage: StorageAdapter) => Promise<TrackingRecord | null>;
21
+ export declare const writeTrackingRecord: (storage: StorageAdapter, record: TrackingRecord) => Promise<void>;
22
+ export declare const clearTrackingRecord: (storage: StorageAdapter) => Promise<void>;
23
+ export declare const detectPlatform: () => "ios" | "android" | undefined;
24
+ /** Where the location library should post: the native sync endpoint, as this session. */
25
+ export declare const nativeDeliveryTarget: (record: {
26
+ baseUrl: string;
27
+ sessionToken: string;
28
+ deviceId?: string;
29
+ }) => NativeDeliveryTarget;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nativeDeliveryTarget = exports.detectPlatform = exports.clearTrackingRecord = exports.writeTrackingRecord = exports.readTrackingRecord = exports.SDK_VERSION = void 0;
4
+ const constants_1 = require("./constants");
5
+ // Read from the manifest so the version reported to the server never drifts
6
+ // from the published one (resolves to the package root from both src/ and dist/).
7
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
8
+ exports.SDK_VERSION = require('../package.json').version;
9
+ const readTrackingRecord = async (storage) => {
10
+ try {
11
+ const raw = await storage.getItem(constants_1.TRACKING_RECORD_KEY);
12
+ if (!raw)
13
+ return null;
14
+ const record = JSON.parse(raw);
15
+ return (record === null || record === void 0 ? void 0 : record.kycId) && (record === null || record === void 0 ? void 0 : record.sessionToken) && (record === null || record === void 0 ? void 0 : record.baseUrl) ? record : null;
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ };
21
+ exports.readTrackingRecord = readTrackingRecord;
22
+ const writeTrackingRecord = async (storage, record) => {
23
+ try {
24
+ await storage.setItem(constants_1.TRACKING_RECORD_KEY, JSON.stringify(record));
25
+ }
26
+ catch {
27
+ /* storage unavailable — tracking still runs, it just won't auto-resume */
28
+ }
29
+ };
30
+ exports.writeTrackingRecord = writeTrackingRecord;
31
+ const clearTrackingRecord = async (storage) => {
32
+ try {
33
+ await storage.removeItem(constants_1.TRACKING_RECORD_KEY);
34
+ }
35
+ catch {
36
+ /* nothing to clear */
37
+ }
38
+ };
39
+ exports.clearTrackingRecord = clearTrackingRecord;
40
+ const detectPlatform = () => {
41
+ try {
42
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
43
+ const { Platform } = require('react-native');
44
+ return (Platform === null || Platform === void 0 ? void 0 : Platform.OS) === 'ios' || (Platform === null || Platform === void 0 ? void 0 : Platform.OS) === 'android'
45
+ ? Platform.OS
46
+ : undefined;
47
+ }
48
+ catch {
49
+ return undefined;
50
+ }
51
+ };
52
+ exports.detectPlatform = detectPlatform;
53
+ /** Where the location library should post: the native sync endpoint, as this session. */
54
+ const nativeDeliveryTarget = (record) => {
55
+ const params = { sdkVersion: exports.SDK_VERSION };
56
+ const platform = (0, exports.detectPlatform)();
57
+ if (platform)
58
+ params.platform = platform;
59
+ if (record.deviceId)
60
+ params.deviceId = record.deviceId;
61
+ return {
62
+ url: `${record.baseUrl.replace(/\/+$/, '')}${constants_1.NATIVE_SYNC_PATH}`,
63
+ headers: { 'x-proxze-session-token': record.sessionToken },
64
+ params,
65
+ };
66
+ };
67
+ exports.nativeDeliveryTarget = nativeDeliveryTarget;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proxze/kyc-react-native",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Proxze Enterprise Address KYC SDK for React Native — passive geofence night verification, consent, evidence upload.",
5
5
  "author": "Sage Grey Technologies Limited",
6
6
  "license": "SEE LICENSE IN LICENSE",