unshared-clientjs-sdk 1.0.0 → 1.0.2
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 +109 -0
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Unshared Labs SDK
|
|
2
|
+
|
|
3
|
+
A lightweight, drop-in SDK for sending secure session and event data to the **Unshared Labs** platform.
|
|
4
|
+
This package is designed for server environments (e.g., Express, Fastify, Next.js API routes) that need to track account sharing activity, session behavior, or suspicious usage patterns.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install unshared-clientjs-sdk
|
|
12
|
+
# or
|
|
13
|
+
yarn add unshared-clientjs-sdk
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Quick Example
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import UnsharedLabsClient from "unshared-clientjs-sdk";
|
|
22
|
+
|
|
23
|
+
const client = new UnsharedLabsClient({
|
|
24
|
+
apiKey: process.env.UNSHARED_LABS_API_KEY!,
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## API
|
|
31
|
+
|
|
32
|
+
### `submitEvent(...)`
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
submitEvent(
|
|
36
|
+
eventType: string,
|
|
37
|
+
userId: string,
|
|
38
|
+
ipAddress: string,
|
|
39
|
+
deviceId: string,
|
|
40
|
+
sessionHash: string,
|
|
41
|
+
userAgent: string,
|
|
42
|
+
clientTimestamp: string,
|
|
43
|
+
eventDetails?: map<String,any> | null
|
|
44
|
+
): Promise<any>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Parameters**
|
|
48
|
+
|
|
49
|
+
* `eventType` — string, e.g. `"login"`, `"heartbeat"`, `"logout"`
|
|
50
|
+
* `userId` — string, unique user identifier (encrypted before sending)
|
|
51
|
+
* `ipAddress` — string, client IP (encrypted)
|
|
52
|
+
* `deviceId` — string, device identifier (encrypted)
|
|
53
|
+
* `sessionHash` — string, session identifier or fingerprint (encrypted)
|
|
54
|
+
* `userAgent` — string
|
|
55
|
+
* `clientTimestamp` — ISO timestamp string (e.g. `new Date().toISOString()`).
|
|
56
|
+
* `eventDetails` — optional map of objects (String,any) of additional details
|
|
57
|
+
|
|
58
|
+
**Returns**: A promise resolving Unshared Lab's DB insert result or rejecting with an error.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Example (Express)
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import express from "express";
|
|
66
|
+
import UnsharedLabsClient from "unshared-clientjs-sdk";
|
|
67
|
+
|
|
68
|
+
const app = express();
|
|
69
|
+
app.use(express.json());
|
|
70
|
+
|
|
71
|
+
const client = new UnsharedLabsClient({
|
|
72
|
+
apiKey: process.env.UNSHARED_LABS_API_KEY!,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
app.post("/login", async (req, res) => {
|
|
76
|
+
const { userId } = req.body;
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
await client.submitEvent(
|
|
80
|
+
"login",
|
|
81
|
+
userId,
|
|
82
|
+
req.ip,
|
|
83
|
+
req.headers["x-device-id"]?.toString() || "unknown-device",
|
|
84
|
+
req.headers["x-session-hash"]?.toString() || "unknown-session",
|
|
85
|
+
req.headers["user-agent"] || "",
|
|
86
|
+
new Date().toISOString(),
|
|
87
|
+
new Map(Object.entries({"example": true, "source": 'test-server' }))
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
res.status(200).json({ message: "Login tracked" });
|
|
91
|
+
} catch (err) {
|
|
92
|
+
res.status(500).json({ error: err instanceof Error ? err.message : err });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
app.listen(3000, () => console.log("Server running on port 3000"));
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT © Unshared Labs
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Support
|
|
108
|
+
|
|
109
|
+
For issues or onboarding help, contact Unshared Labs support.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unshared-clientjs-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/client.js",
|
|
6
6
|
"types": "dist/client.d.ts",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"test-server": "ts-node test-server/server.ts"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
16
17
|
],
|
|
17
18
|
"keywords": [],
|
|
18
19
|
"author": "",
|