unshared-clientjs-sdk 1.0.1 → 1.0.3
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/dist/client.d.ts +2 -0
- package/dist/client.js +3 -2
- 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/dist/client.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export interface UnsharedLabsClientConfig {
|
|
2
2
|
apiKey: string;
|
|
3
|
+
clientId: string;
|
|
3
4
|
baseUrl?: string;
|
|
4
5
|
}
|
|
5
6
|
export default class UnsharedLabsClient {
|
|
6
7
|
private _UNSHAREDLABS_DEFAULT_URL;
|
|
7
8
|
private _UNSHAREDLABS_INTERNAL_CLIENT;
|
|
8
9
|
private _apiKey;
|
|
10
|
+
private _clientId;
|
|
9
11
|
constructor(config: UnsharedLabsClientConfig);
|
|
10
12
|
private _getSupabaseClient;
|
|
11
13
|
submitEvent(eventType: string, userId: string, ipAddress: string, deviceId: string, sessionHash: string, userAgent: string, clientTimestamp: string, eventDetails?: Map<string, any> | null): Promise<any>;
|
package/dist/client.js
CHANGED
|
@@ -4,9 +4,10 @@ const supabase_js_1 = require("@supabase/supabase-js");
|
|
|
4
4
|
const util_1 = require("./util");
|
|
5
5
|
class UnsharedLabsClient {
|
|
6
6
|
constructor(config) {
|
|
7
|
-
this._UNSHAREDLABS_DEFAULT_URL = '
|
|
7
|
+
this._UNSHAREDLABS_DEFAULT_URL = atob('aHR0cHM6Ly95c3Vmem5jZXR0d2VyYnlhbXlneC5zdXBhYmFzZS5jbwo=');
|
|
8
8
|
let url = config.baseUrl || this._UNSHAREDLABS_DEFAULT_URL;
|
|
9
9
|
this._apiKey = config.apiKey;
|
|
10
|
+
this._clientId = atob(config.clientId);
|
|
10
11
|
this._UNSHAREDLABS_INTERNAL_CLIENT = this._getSupabaseClient(url, this._apiKey);
|
|
11
12
|
}
|
|
12
13
|
_getSupabaseClient(url, apiKey) {
|
|
@@ -36,7 +37,7 @@ class UnsharedLabsClient {
|
|
|
36
37
|
event_details: encryptedEventDetails,
|
|
37
38
|
};
|
|
38
39
|
const { data, error } = await this._UNSHAREDLABS_INTERNAL_CLIENT
|
|
39
|
-
.from(
|
|
40
|
+
.from(this._clientId)
|
|
40
41
|
.insert(body);
|
|
41
42
|
if (error) {
|
|
42
43
|
throw error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unshared-clientjs-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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": "",
|