sockress-client 0.1.4 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +61 -0
  2. package/package.json +25 -2
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Sockress Client SDK
2
+
3
+ sockress-client is the companion SDK for Sockress-powered backends. It automatically prefers a WebSocket transport (sharing the same request/response semantics as HTTP) and silently falls back to etch when a socket is unavailable. Multipart uploads (FormData) are serialized over the wire, so you can use a single API surface for avatars, profile forms, and realtime commands.
4
+
5
+ Created by **Also Coder** · [alsocoder.com](https://alsocoder.com) · [github.com/alsocoders](https://github.com/alsocoders)
6
+
7
+ ## Installation
8
+
9
+ `ash
10
+ npm install sockress-client
11
+ `
12
+
13
+ ## Usage
14
+
15
+ ` s
16
+ import { sockressClient } from 'sockress-client';
17
+
18
+ const api = sockressClient({
19
+ baseUrl: 'http://localhost:5051',
20
+ autoConnect: true,
21
+ preferSocket: true
22
+ });
23
+
24
+ const login = async () => {
25
+ const response = await api.post('/api/auth/login', {
26
+ body: { email: 'demo@sockress.dev', password: 'pass123' }
27
+ });
28
+
29
+ console.log('token', response.body.token);
30
+ };
31
+ `
32
+
33
+ ### File Uploads
34
+
35
+ ` s
36
+ export async function uploadAvatar(file, token) {
37
+ const formData = new FormData();
38
+ formData.append('avatar', file);
39
+
40
+ const response = await api.request({
41
+ path: '/api/profile/avatar',
42
+ method: 'POST',
43
+ body: formData,
44
+ headers: { Authorization: Bearer }
45
+ });
46
+
47
+ return response.body;
48
+ }
49
+ `
50
+
51
+ ### Events
52
+
53
+ ` s
54
+ api.on('open', () => console.log('socket ready')); // when the WebSocket connects
55
+ api.on('error', (err) => console.error(err));
56
+ api.on('reconnect', ({ attempt }) => console.log('retry', attempt));
57
+ `
58
+
59
+ ---
60
+
61
+ Questions or feedback? Ping [alsocoder.com](https://alsocoder.com) or [@alsocoders](https://github.com/alsocoders).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sockress-client",
3
- "version": "0.1.4",
4
- "description": "Client SDK for Sockress with socket-first transport and HTTP fallback",
3
+ "version": "0.1.5",
4
+ "description": "Socket-first client SDK for Sockress servers with automatic HTTP fallback and FormData serialization.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "commonjs",
@@ -16,6 +16,29 @@
16
16
  "build": "tsc -p tsconfig.json",
17
17
  "prepublishOnly": "npm run build"
18
18
  },
19
+ "author": {
20
+ "name": "Also Coder",
21
+ "email": "hello@alsocoder.com",
22
+ "url": "https://alsocoder.com"
23
+ },
24
+ "homepage": "https://alsocoder.com",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/alsocoders/sockress"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/alsocoders/sockress/issues"
31
+ },
32
+ "keywords": [
33
+ "sockress",
34
+ "websocket",
35
+ "http",
36
+ "client",
37
+ "upload",
38
+ "realtime",
39
+ "nodejs",
40
+ "browser"
41
+ ],
19
42
  "dependencies": {
20
43
  "nanoid": "^5.0.7"
21
44
  },