spotny-sdk 0.3.7 → 0.3.9
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/README.md +45 -134
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# spotny-sdk
|
|
2
2
|
|
|
3
|
-
A React Native SDK for
|
|
3
|
+
A React Native SDK for real-time proximity experiences. Detects nearby points of interest and fires location events on iOS and Android.
|
|
4
4
|
|
|
5
5
|
> Requires **React Native 0.73+** with the New Architecture (Turbo Modules) enabled.
|
|
6
6
|
|
|
@@ -24,11 +24,11 @@ Add the following keys to your `Info.plist`:
|
|
|
24
24
|
|
|
25
25
|
```xml
|
|
26
26
|
<key>NSLocationWhenInUseUsageDescription</key>
|
|
27
|
-
<string>We use your location to detect nearby
|
|
27
|
+
<string>We use your location to detect nearby points of interest.</string>
|
|
28
28
|
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
|
|
29
|
-
<string>We use your location in the background to detect nearby
|
|
29
|
+
<string>We use your location in the background to detect nearby points of interest.</string>
|
|
30
30
|
<key>NSBluetoothAlwaysUsageDescription</key>
|
|
31
|
-
<string>We use Bluetooth to
|
|
31
|
+
<string>We use Bluetooth to detect nearby points of interest.</string>
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
Enable **Background Modes** in Xcode → your app target → **Signing & Capabilities** → **+ Capability** → Background Modes:
|
|
@@ -36,7 +36,7 @@ Enable **Background Modes** in Xcode → your app target → **Signing & Capabil
|
|
|
36
36
|
- ✅ Location updates
|
|
37
37
|
- ✅ Uses Bluetooth LE accessories
|
|
38
38
|
|
|
39
|
-
> **
|
|
39
|
+
> **Note:** Background scanning requires the _Location updates_ background mode. The SDK works without it for foreground-only use.
|
|
40
40
|
|
|
41
41
|
### Android
|
|
42
42
|
|
|
@@ -60,32 +60,28 @@ import {
|
|
|
60
60
|
configure,
|
|
61
61
|
startScanner,
|
|
62
62
|
stopScanner,
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
addProximityListener,
|
|
64
|
+
addLocationEventListener,
|
|
65
65
|
} from 'spotny-sdk';
|
|
66
66
|
|
|
67
67
|
export default function App() {
|
|
68
68
|
useEffect(() => {
|
|
69
|
-
|
|
70
|
-
configure({ maxDetectionDistance: 10 });
|
|
71
|
-
|
|
72
|
-
// Start scanning with a unique device/user identifier
|
|
69
|
+
configure({ source: 'nike', maxDetectionDistance: 10 });
|
|
73
70
|
startScanner('device-uuid-here', /* userId */ null);
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
console.log('Beacons in range:', beacons);
|
|
72
|
+
const proxSub = addProximityListener((items) => {
|
|
73
|
+
console.log('Nearby:', items);
|
|
78
74
|
});
|
|
79
75
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
console.log(
|
|
76
|
+
const locationSub = addLocationEventListener(({ event, zone }) => {
|
|
77
|
+
if (event === 'enter') console.log('Entered zone', zone);
|
|
78
|
+
if (event === 'exit') console.log('Left zone', zone);
|
|
83
79
|
});
|
|
84
80
|
|
|
85
81
|
return () => {
|
|
86
82
|
stopScanner();
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
proxSub.remove();
|
|
84
|
+
locationSub.remove();
|
|
89
85
|
};
|
|
90
86
|
}, []);
|
|
91
87
|
|
|
@@ -97,18 +93,18 @@ export default function App() {
|
|
|
97
93
|
|
|
98
94
|
## API Reference
|
|
99
95
|
|
|
100
|
-
### Core
|
|
96
|
+
### Core
|
|
101
97
|
|
|
102
98
|
#### `startScanner(userUUID, userId?)`
|
|
103
99
|
|
|
104
|
-
Starts
|
|
100
|
+
Starts proximity scanning.
|
|
105
101
|
|
|
106
|
-
| Parameter | Type | Required | Description
|
|
107
|
-
| ---------- | ---------------- | -------- |
|
|
108
|
-
| `userUUID` | `string` | Yes | Unique identifier for this
|
|
109
|
-
| `userId` | `number \| null` | No | Authenticated user ID
|
|
102
|
+
| Parameter | Type | Required | Description |
|
|
103
|
+
| ---------- | ---------------- | -------- | ----------------------------------------- |
|
|
104
|
+
| `userUUID` | `string` | Yes | Unique identifier for this device/session |
|
|
105
|
+
| `userId` | `number \| null` | No | Authenticated user ID |
|
|
110
106
|
|
|
111
|
-
Returns `Promise<string
|
|
107
|
+
Returns `Promise<string>`.
|
|
112
108
|
|
|
113
109
|
```ts
|
|
114
110
|
await startScanner('550e8400-e29b-41d4-a716-446655440000', 42);
|
|
@@ -118,23 +114,15 @@ await startScanner('550e8400-e29b-41d4-a716-446655440000', 42);
|
|
|
118
114
|
|
|
119
115
|
#### `stopScanner()`
|
|
120
116
|
|
|
121
|
-
Stops scanning
|
|
117
|
+
Stops scanning and clears all state.
|
|
122
118
|
|
|
123
119
|
Returns `Promise<string>`.
|
|
124
120
|
|
|
125
|
-
```ts
|
|
126
|
-
await stopScanner();
|
|
127
|
-
```
|
|
128
|
-
|
|
129
121
|
---
|
|
130
122
|
|
|
131
123
|
#### `isScanning()`
|
|
132
124
|
|
|
133
|
-
Returns `Promise<boolean
|
|
134
|
-
|
|
135
|
-
```ts
|
|
136
|
-
const scanning = await isScanning();
|
|
137
|
-
```
|
|
125
|
+
Returns `Promise<boolean>`.
|
|
138
126
|
|
|
139
127
|
---
|
|
140
128
|
|
|
@@ -142,19 +130,15 @@ const scanning = await isScanning();
|
|
|
142
130
|
|
|
143
131
|
#### `configure(config)`
|
|
144
132
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
| Option | Type | Default | Description |
|
|
148
|
-
| ---------------------- | -------- | ------- | ---------------------------------------- |
|
|
149
|
-
| `maxDetectionDistance` | `number` | `8.0` | Maximum beacon detection radius (metres) |
|
|
150
|
-
| `source` | `string` | – | Company / brand using the SDK (e.g. `'nike'`). Sent with every backend request. |
|
|
151
|
-
|
|
152
|
-
> The backend URL and Kontakt.io API key are fixed internally and cannot be overridden by consumers.
|
|
133
|
+
Call **before** `startScanner`.
|
|
153
134
|
|
|
154
|
-
|
|
135
|
+
| Option | Type | Default | Description |
|
|
136
|
+
| ---------------------- | -------- | ------- | -------------------------------------------- |
|
|
137
|
+
| `source` | `string` | – | Your brand or app identifier (e.g. `'nike'`) |
|
|
138
|
+
| `maxDetectionDistance` | `number` | `8.0` | Detection radius in metres |
|
|
155
139
|
|
|
156
140
|
```ts
|
|
157
|
-
await configure({
|
|
141
|
+
await configure({ source: 'nike', maxDetectionDistance: 10 });
|
|
158
142
|
```
|
|
159
143
|
|
|
160
144
|
---
|
|
@@ -163,139 +147,66 @@ await configure({ maxDetectionDistance: 12, source: 'nike' });
|
|
|
163
147
|
|
|
164
148
|
#### `requestNotificationPermissions()` _(iOS only)_
|
|
165
149
|
|
|
166
|
-
|
|
150
|
+
Requests local notification permissions.
|
|
167
151
|
|
|
168
152
|
Returns `Promise<string>`.
|
|
169
153
|
|
|
170
|
-
```ts
|
|
171
|
-
await requestNotificationPermissions();
|
|
172
|
-
```
|
|
173
|
-
|
|
174
154
|
---
|
|
175
155
|
|
|
176
156
|
### Event Listeners
|
|
177
157
|
|
|
178
158
|
#### `addBeaconsRangedListener(callback)`
|
|
179
159
|
|
|
180
|
-
Fires
|
|
160
|
+
Fires when nearby items are detected (approximately every second).
|
|
181
161
|
|
|
182
162
|
```ts
|
|
183
|
-
const
|
|
184
|
-
beacons.forEach((
|
|
185
|
-
console.log(`${
|
|
163
|
+
const sub = addBeaconsRangedListener(({ beacons }) => {
|
|
164
|
+
beacons.forEach((item) => {
|
|
165
|
+
console.log(`${item.distance.toFixed(1)} m — ${item.proximity}`);
|
|
186
166
|
});
|
|
187
167
|
});
|
|
188
168
|
|
|
189
|
-
//
|
|
190
|
-
subscription.remove();
|
|
169
|
+
sub.remove(); // when done
|
|
191
170
|
```
|
|
192
171
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
| Field | Type | Description |
|
|
196
|
-
| --------- | -------------- | ------------------------ |
|
|
197
|
-
| `beacons` | `BeaconData[]` | Array of visible beacons |
|
|
198
|
-
| `region` | `string` | Beacon region identifier |
|
|
199
|
-
|
|
200
|
-
**`BeaconData`:**
|
|
172
|
+
Each item contains:
|
|
201
173
|
|
|
202
174
|
| Field | Type | Description |
|
|
203
175
|
| ----------- | -------- | --------------------------------------------------- |
|
|
204
|
-
| `uuid` | `string` | Proximity UUID |
|
|
205
|
-
| `major` | `number` | Major value |
|
|
206
|
-
| `minor` | `number` | Minor value |
|
|
207
176
|
| `distance` | `number` | Estimated distance in metres |
|
|
208
|
-
| `rssi` | `number` | Signal strength (dBm) |
|
|
209
177
|
| `proximity` | `string` | `'immediate'` \| `'near'` \| `'far'` \| `'unknown'` |
|
|
210
178
|
|
|
211
179
|
---
|
|
212
180
|
|
|
213
181
|
#### `addBeaconRegionListener(callback)`
|
|
214
182
|
|
|
215
|
-
Fires
|
|
183
|
+
Fires when the user enters or exits a zone. Works in foreground, background, and terminated state (iOS).
|
|
216
184
|
|
|
217
185
|
```ts
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
if (event === 'exit') console.log('Exited', region);
|
|
186
|
+
const sub = addBeaconRegionListener(({ event, region, state }) => {
|
|
187
|
+
console.log(event, region); // 'enter' | 'exit' | 'determined'
|
|
221
188
|
});
|
|
222
189
|
|
|
223
|
-
//
|
|
224
|
-
subscription.remove();
|
|
190
|
+
sub.remove(); // when done
|
|
225
191
|
```
|
|
226
192
|
|
|
227
|
-
**Callback payload — `BeaconRegionEvent`:**
|
|
228
|
-
|
|
229
193
|
| Field | Type | Description |
|
|
230
194
|
| -------- | -------- | ---------------------------------------------------------- |
|
|
231
|
-
| `region` | `string` | Region identifier |
|
|
232
195
|
| `event` | `string` | `'enter'` \| `'exit'` \| `'determined'` |
|
|
196
|
+
| `region` | `string` | Zone identifier |
|
|
233
197
|
| `state` | `string` | `'inside'` \| `'outside'` \| `'unknown'` (determined only) |
|
|
234
198
|
|
|
235
199
|
---
|
|
236
200
|
|
|
237
|
-
### Debounce Helpers
|
|
238
|
-
|
|
239
|
-
These let you tune how often repeated proximity events are emitted for the same beacon.
|
|
240
|
-
|
|
241
|
-
#### `setDebounceInterval(seconds)`
|
|
242
|
-
|
|
243
|
-
Sets the minimum gap (in seconds) between proximity events for the same beacon.
|
|
244
|
-
|
|
245
|
-
```ts
|
|
246
|
-
await setDebounceInterval(30); // fire at most once per 30 s per beacon
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
#### `clearDebounceCache()`
|
|
250
|
-
|
|
251
|
-
Resets cooldown state for all beacons, allowing them to fire again immediately.
|
|
252
|
-
|
|
253
|
-
```ts
|
|
254
|
-
await clearDebounceCache();
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
#### `getDebounceStatus()`
|
|
258
|
-
|
|
259
|
-
Returns the current cooldown state for all tracked beacons.
|
|
260
|
-
|
|
261
|
-
```ts
|
|
262
|
-
const status = await getDebounceStatus();
|
|
263
|
-
console.log(status);
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
---
|
|
267
|
-
|
|
268
201
|
### Debug Helpers
|
|
269
202
|
|
|
270
203
|
#### `getDebugLogs()`
|
|
271
204
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
```ts
|
|
275
|
-
const logs = await getDebugLogs();
|
|
276
|
-
console.log(logs);
|
|
277
|
-
```
|
|
205
|
+
Returns on-device debug logs as a string.
|
|
278
206
|
|
|
279
207
|
#### `clearDebugLogs()`
|
|
280
208
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
```ts
|
|
284
|
-
await clearDebugLogs();
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
---
|
|
288
|
-
|
|
289
|
-
## TypeScript Types
|
|
290
|
-
|
|
291
|
-
```ts
|
|
292
|
-
import type {
|
|
293
|
-
BeaconData,
|
|
294
|
-
BeaconRangedEvent,
|
|
295
|
-
BeaconRegionEvent,
|
|
296
|
-
SpotnySdkConfig,
|
|
297
|
-
} from 'spotny-sdk';
|
|
298
|
-
```
|
|
209
|
+
Clears on-device debug logs.
|
|
299
210
|
|
|
300
211
|
---
|
|
301
212
|
|
|
@@ -303,7 +214,7 @@ import type {
|
|
|
303
214
|
|
|
304
215
|
| Feature | iOS | Android |
|
|
305
216
|
| ------------------------ | --- | ------- |
|
|
306
|
-
|
|
|
217
|
+
| Zone monitoring | ✅ | ✅ |
|
|
307
218
|
| Background scanning | ✅ | ✅ |
|
|
308
219
|
| Terminated-state wakeup | ✅ | ✅ |
|
|
309
220
|
| Notification permissions | ✅ | – |
|
|
@@ -25,7 +25,7 @@ export type BeaconRegionEvent = {
|
|
|
25
25
|
export type SpotnySdkConfig = {
|
|
26
26
|
/** Maximum BLE detection distance in metres (default: 8.0) */
|
|
27
27
|
maxDetectionDistance?: number;
|
|
28
|
-
/**
|
|
28
|
+
/** Identifier for your brand or app (e.g. 'nike'). */
|
|
29
29
|
source?: string;
|
|
30
30
|
};
|
|
31
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY;;;CAGf,CAAC;AAIX,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,sCAAsC;IACtC,KAAK,EAAE,OAAO,GAAG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7C;AAED,uDAAuD;AACvD,wBAAgB,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAE7C;AAID;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAElE;AAID,gEAAgE;AAChE,wBAAgB,8BAA8B,IAAI,OAAO,CAAC,MAAM,CAAC,CAEhE;AAID,yCAAyC;AACzC,wBAAgB,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC,CAE9C;AAED,2CAA2C;AAC3C,wBAAgB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAEhD;AAID,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAErE;AAED,2DAA2D;AAC3D,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC,CAEpD;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC,CAEnD;AAID;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,4CAM7C;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,4CAM7C"}
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -35,7 +35,7 @@ export type BeaconRegionEvent = {
|
|
|
35
35
|
export type SpotnySdkConfig = {
|
|
36
36
|
/** Maximum BLE detection distance in metres (default: 8.0) */
|
|
37
37
|
maxDetectionDistance?: number;
|
|
38
|
-
/**
|
|
38
|
+
/** Identifier for your brand or app (e.g. 'nike'). */
|
|
39
39
|
source?: string;
|
|
40
40
|
};
|
|
41
41
|
|