spotny-sdk 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.

Potentially problematic release.


This version of spotny-sdk might be problematic. Click here for more details.

package/src/index.tsx ADDED
@@ -0,0 +1,141 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
+ import NativeSpotnySdk from './NativeSpotnySdk';
3
+
4
+ // ── Event names ──────────────────────────────────────────────────────────────
5
+ export const SpotnyEvents = {
6
+ ON_BEACONS_RANGED: 'onBeaconsRanged',
7
+ ON_BEACON_REGION_EVENT: 'onBeaconRegionEvent',
8
+ } as const;
9
+
10
+ // ── Types ────────────────────────────────────────────────────────────────────
11
+
12
+ export type BeaconData = {
13
+ uuid: string;
14
+ major: number;
15
+ minor: number;
16
+ /** Estimated distance in metres */
17
+ distance: number;
18
+ rssi: number;
19
+ /** 'immediate' | 'near' | 'far' | 'unknown' */
20
+ proximity: string;
21
+ };
22
+
23
+ export type BeaconRangedEvent = {
24
+ beacons: BeaconData[];
25
+ region: string;
26
+ };
27
+
28
+ export type BeaconRegionEvent = {
29
+ region: string;
30
+ /** 'enter' | 'exit' | 'determined' */
31
+ event: 'enter' | 'exit' | 'determined';
32
+ state?: 'inside' | 'outside' | 'unknown';
33
+ };
34
+
35
+ export type SpotnySdkConfig = {
36
+ /** Base URL for the backend API (default: https://api.spotny.app) */
37
+ backendURL?: string;
38
+ /** Maximum BLE detection distance in metres (default: 8.0) */
39
+ maxDetectionDistance?: number;
40
+ };
41
+
42
+ // ── Internal event emitter ───────────────────────────────────────────────────
43
+ const eventEmitter = new NativeEventEmitter(NativeModules.SpotnySdk);
44
+
45
+ // ── Core scanning ────────────────────────────────────────────────────────────
46
+
47
+ /**
48
+ * Start beacon scanning.
49
+ * @param userUUID A unique string identifying this installation / user session.
50
+ * @param userId Optional authenticated user ID.
51
+ */
52
+ export function startScanner(
53
+ userUUID: string,
54
+ userId?: number | null
55
+ ): Promise<string> {
56
+ return NativeSpotnySdk.startScanner(userUUID, userId ?? null);
57
+ }
58
+
59
+ /** Stop beacon scanning and clean up all state. */
60
+ export function stopScanner(): Promise<string> {
61
+ return NativeSpotnySdk.stopScanner();
62
+ }
63
+
64
+ /** Returns `true` if the SDK is currently scanning. */
65
+ export function isScanning(): Promise<boolean> {
66
+ return NativeSpotnySdk.isScanning();
67
+ }
68
+
69
+ // ── Configuration ────────────────────────────────────────────────────────────
70
+
71
+ /**
72
+ * Override SDK configuration at runtime.
73
+ * Must be called **before** `startScanner`.
74
+ */
75
+ export function configure(config: SpotnySdkConfig): Promise<string> {
76
+ return NativeSpotnySdk.configure(config as Object);
77
+ }
78
+
79
+ // ── Permissions ──────────────────────────────────────────────────────────────
80
+
81
+ /** (iOS) Prompt the user for local-notification permissions. */
82
+ export function requestNotificationPermissions(): Promise<string> {
83
+ return NativeSpotnySdk.requestNotificationPermissions();
84
+ }
85
+
86
+ // ── Debug helpers ─────────────────────────────────────────────────────────────
87
+
88
+ /** Read the on-device debug log file. */
89
+ export function getDebugLogs(): Promise<string> {
90
+ return NativeSpotnySdk.getDebugLogs();
91
+ }
92
+
93
+ /** Delete the on-device debug log file. */
94
+ export function clearDebugLogs(): Promise<string> {
95
+ return NativeSpotnySdk.clearDebugLogs();
96
+ }
97
+
98
+ // ── Debounce helpers ──────────────────────────────────────────────────────────
99
+
100
+ /** Override the proximity-event debounce interval (seconds). */
101
+ export function setDebounceInterval(interval: number): Promise<string> {
102
+ return NativeSpotnySdk.setDebounceInterval(interval);
103
+ }
104
+
105
+ /** Clear the debounce / cooldown cache for all beacons. */
106
+ export function clearDebounceCache(): Promise<string> {
107
+ return NativeSpotnySdk.clearDebounceCache();
108
+ }
109
+
110
+ /** Return the current debounce status for all tracked beacons. */
111
+ export function getDebounceStatus(): Promise<Object> {
112
+ return NativeSpotnySdk.getDebounceStatus();
113
+ }
114
+
115
+ // ── Event subscriptions ───────────────────────────────────────────────────────
116
+
117
+ /**
118
+ * Subscribe to continuous ranging updates.
119
+ * The callback fires roughly every second while beacons are in range.
120
+ */
121
+ export function addBeaconsRangedListener(
122
+ callback: (event: BeaconRangedEvent) => void
123
+ ) {
124
+ return eventEmitter.addListener(
125
+ SpotnyEvents.ON_BEACONS_RANGED,
126
+ callback as (...args: readonly object[]) => unknown
127
+ );
128
+ }
129
+
130
+ /**
131
+ * Subscribe to region enter/exit events.
132
+ * These fire in all app states (foreground, background, terminated on iOS).
133
+ */
134
+ export function addBeaconRegionListener(
135
+ callback: (event: BeaconRegionEvent) => void
136
+ ) {
137
+ return eventEmitter.addListener(
138
+ SpotnyEvents.ON_BEACON_REGION_EVENT,
139
+ callback as (...args: readonly object[]) => unknown
140
+ );
141
+ }