unshared-frontend-sdk 2.0.0-rc.3 → 2.0.0-rc.5
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 +21 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,12 +10,7 @@ Browser SDK for [Unshared Labs](https://unsharedlabs.com) — collects a device
|
|
|
10
10
|
npm install unshared-frontend-sdk
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Or via CDN (no build step)
|
|
14
|
-
|
|
15
|
-
```html
|
|
16
|
-
<script src="https://unpkg.com/unshared-frontend-sdk/dist/index.umd.js"></script>
|
|
17
|
-
<!-- Available as window.UnsharedLabsBrowser -->
|
|
18
|
-
```
|
|
13
|
+
Or via CDN (no build step) — see [CDN / UMD usage](#cdn--umd-usage) below for the complete example.
|
|
19
14
|
|
|
20
15
|
---
|
|
21
16
|
|
|
@@ -24,14 +19,12 @@ Or via CDN (no build step):
|
|
|
24
19
|
```typescript
|
|
25
20
|
import { UnsharedLabsBrowser } from 'unshared-frontend-sdk';
|
|
26
21
|
|
|
27
|
-
//
|
|
28
|
-
const client = new UnsharedLabsBrowser({
|
|
29
|
-
baseUrl: 'https://yourapp.com', // your backend, not Unshared Labs
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// Same-origin: omit baseUrl
|
|
22
|
+
// Same-origin (frontend served by the same backend): omit baseUrl
|
|
33
23
|
const client = new UnsharedLabsBrowser({});
|
|
34
24
|
|
|
25
|
+
// Cross-origin (separate domains): set baseUrl via env var
|
|
26
|
+
// const client = new UnsharedLabsBrowser({ baseUrl: process.env.BACKEND_URL });
|
|
27
|
+
|
|
35
28
|
// On page load — fire and forget
|
|
36
29
|
const fingerprint = await client.collect();
|
|
37
30
|
client.submitFingerprintEvent(fingerprint, { userId: currentUser?.id });
|
|
@@ -45,9 +38,9 @@ That's it. The SDK handles retries, timeouts, and errors silently.
|
|
|
45
38
|
|
|
46
39
|
```typescript
|
|
47
40
|
new UnsharedLabsBrowser({
|
|
48
|
-
baseUrl:
|
|
49
|
-
maxRetries: 3,
|
|
50
|
-
timeout: 30_000,
|
|
41
|
+
baseUrl: process.env.BACKEND_URL, // optional — omit for same-origin
|
|
42
|
+
maxRetries: 3, // optional, default: 3
|
|
43
|
+
timeout: 30_000, // optional, default: 30s per attempt
|
|
51
44
|
});
|
|
52
45
|
```
|
|
53
46
|
|
|
@@ -104,10 +97,15 @@ The SDK sends fingerprints to `{baseUrl}/unshared/submit-fingerprint-event`. You
|
|
|
104
97
|
|
|
105
98
|
```typescript
|
|
106
99
|
// On your Express backend
|
|
100
|
+
import express from 'express';
|
|
101
|
+
import { UnsharedLabsClient } from 'unshared-clientjs-sdk';
|
|
107
102
|
import { createUnsharedMiddleware } from 'unshared-clientjs-sdk/middleware';
|
|
108
103
|
|
|
104
|
+
const app = express();
|
|
105
|
+
const unshared = new UnsharedLabsClient({ apiKey: process.env.UNSHARED_API_KEY });
|
|
106
|
+
|
|
109
107
|
app.use(express.json());
|
|
110
|
-
app.use(createUnsharedMiddleware(
|
|
108
|
+
app.use(createUnsharedMiddleware(unshared));
|
|
111
109
|
```
|
|
112
110
|
|
|
113
111
|
---
|
|
@@ -129,12 +127,15 @@ Retries happen automatically on network errors, timeouts, and server errors (5xx
|
|
|
129
127
|
|
|
130
128
|
## CDN / UMD usage
|
|
131
129
|
|
|
130
|
+
The UMD bundle exposes a `window.UnsharedLabsBrowser` namespace object. Destructure the class from it first:
|
|
131
|
+
|
|
132
132
|
```html
|
|
133
|
-
<script src="https://unpkg.com/unshared-frontend-sdk/dist/index.umd.js"></script>
|
|
133
|
+
<script src="https://unpkg.com/unshared-frontend-sdk@2.0.0-rc.4/dist/index.umd.js"></script>
|
|
134
134
|
<script>
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
}
|
|
135
|
+
const { UnsharedLabsBrowser } = window.UnsharedLabsBrowser;
|
|
136
|
+
|
|
137
|
+
// Omit baseUrl for same-origin. Set it for cross-origin: { baseUrl: 'https://api.example.com' }
|
|
138
|
+
const client = new UnsharedLabsBrowser({});
|
|
138
139
|
|
|
139
140
|
client.collect().then(fp => {
|
|
140
141
|
client.submitFingerprintEvent(fp);
|
package/package.json
CHANGED