mirror of
https://github.com/Rolands-Laucis/Socio.git
synced 2026-05-21 06:46:19 -06:00
upd
This commit is contained in:
parent
eb1fb157fc
commit
16fddfb8f3
3 changed files with 16 additions and 17 deletions
|
|
@ -1,7 +1,7 @@
|
|||
# Simple Documentation for Socio usage.
|
||||
##### Those that know, do. Those that understand, teach. /Aristotle/
|
||||
|
||||
### Overview
|
||||
## Overview
|
||||
|
||||
* [WS](https://www.npmjs.com/package/ws) Socio uses on the server.
|
||||
* [The WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) Socio uses on the browser.
|
||||
|
|
@ -15,7 +15,7 @@ The ``./core/secure.ts`` file contains logic to be run on a backend server. It e
|
|||
|
||||
Encryption and decryption uses the AES-256-GCM algorithm (symmetric encryption), which guarantees Confidentiality - cannot be read; Integrity - cannot be altered; and Authenticity - server can verify the author of the created cypher text.
|
||||
|
||||
### SQL and NoSQL
|
||||
## SQL and NoSQL
|
||||
Currently the lib has been developed with a main focus on SQL queries being written on the frontend. This matters, bcs i parse the sent strings with the assumption that they are valid SQL syntax. However, the lib now also supports a NoSQL paradigm in the form of what i call "Server Props".
|
||||
|
||||
"Server props" are a way for the backend to set up a (serializable) JS object, that can be subscribed to and manipulated by clients. Esentially creating an automagically synced value across the backend and all clients. Ofc you may alter the prop on the backend as well at any time. The safety of its data is ensured by you. When registering a new prop to SocioServer, you can supply an "assigner" function, within which it is your responsibility to validate the incoming new value and set it by whatever logic and report back to SocioServer, that the operation was successful or not. See ()[#Server-props] for more details.
|
||||
|
|
@ -144,8 +144,9 @@ const socserv = new SocioServer({ port: 3000, perMessageDeflate }, {...} );
|
|||
```
|
||||
|
||||
#### Session Timeouts (session max age since last seen active)
|
||||
Simply declare a server config object with default options.
|
||||
|
||||
```ts
|
||||
//simply declare a server config object with options.
|
||||
const socserv = new SocioServer({ ... }, {
|
||||
...,
|
||||
session_defaults:{
|
||||
|
|
@ -159,6 +160,8 @@ const socserv = new SocioServer({ ... }, {
|
|||
```
|
||||
If you want to have a fixed time period timeout since connection, you can do that yourself with server hooks or other ways. Set up a client_id and connection timestamp. And loop through checks on sessions in your own timer. Calling SocioSession.CloseConnection() will terminate the WS conn and clean up all associated SocioServer data structures.
|
||||
|
||||
You can quite easily mimic HTTP cookie sessions on whatever backend by using SocioServer hooks with SocioSession id's.
|
||||
|
||||
### Setup of ``SocioClient``
|
||||
|
||||
When using SocioSecurity, but advised to always do this, the "socio" [JS Template Literal Tag](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) must be used, though it doesnt do much. It is just used to conveniently tag and later find socio strings within source code with regex during the encryption procedure.
|
||||
|
|
|
|||
12
README.md
12
README.md
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
* <a href="https://www.youtube.com/watch?v=iJIC9B3cKME&ab_channel=CepuminsLV" target="_blank">3 min video - Introduction demo.</a>
|
||||
* <a href="https://www.youtube.com/watch?v=t8_QBzk5bUk" target="_blank">16 min video - Getting started with Socio 0.7, SvelteKit, Vite.</a>
|
||||
|
||||
---
|
||||
* [Basic Demo project](https://github.com/Rolands-Laucis/Socio/blob/master/demos/basic/readme.md) - interactive bare-bones demo project.
|
||||
* [Secure Full-Stack Framework Demo project](https://github.com/Rolands-Laucis/Socio/tree/master/demos/full-stack_framework#readme) - interactive demo project with SvelteKit and Vite.
|
||||
* [Simple Documentation](https://github.com/Rolands-Laucis/Socio/blob/master/Documentation.md) - page to see direct examples and explanations of how to use various parts of the lib.
|
||||
* [Real-time rent prices in Riga, Latvia](http://riga.rolandslaucis.lv/) made by me. SvelteKit, Vite, Socio, NginX, Ubuntu server.
|
||||
|
||||
---
|
||||
No more API middleware and backend DB interfacing functions and wrappers and handlers. Write your SQL queries on the frontend and have their results be automagically refreshed on all clients when a resource is changed on the server DB. This is secure.
|
||||
|
||||
Ready for use in your small to mid sized web app 🥰 feedback is welcome.
|
||||
|
|
@ -44,7 +44,7 @@ async function QueryWrap(client: SocioSession, id: id, sql: string, params: obje
|
|||
//sanatize dynamic params!
|
||||
}
|
||||
|
||||
const socsec = new SocioSecurity({ secure_private_key: '...', logging:{verbose:true} }); //for decrypting incoming queries. This same key is used for encrypting the source files when you build and bundle them.
|
||||
const socsec = new SocioSecurity({ secure_private_key: '...', logging:{verbose:true} }); //for decrypting incoming queries. This same key is used for encrypting the source files when you build and bundle them. Same in the Vite plugin.
|
||||
const socserv = new SocioServer({ port: 3000 }, { DB_query_function: QueryWrap as QueryFunction, socio_security: socsec, logging:{verbose:true} }); //creates localhost:3000 web socket server
|
||||
```
|
||||
```ts
|
||||
|
|
@ -71,7 +71,7 @@ import { SocioSecurityVitePlugin } from 'socio/dist/secure';
|
|||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
SocioSecurityVitePlugin({ secure_private_key: 'skk#$U#Y$7643GJHKGDHJH#$K#$HLI#H$KBKDBDFKU34534', logging:{verbose:true} }),
|
||||
SocioSecurityVitePlugin({ secure_private_key: '...', logging:{verbose:true} }), //same key as in SocioSecurity
|
||||
sveltekit()
|
||||
]
|
||||
});
|
||||
|
|
@ -91,8 +91,6 @@ The use of the Socio lib **does not** prohibit the use of standard HTTP technolo
|
|||
|
||||
For SQL queries, the automagic happens because i regex parse the strings myself with simple patterns. The most basic usecases should be covered, but more complex SQL queries are not - situations like: nested queries and multiple queries in a single string. Only table names are extracted, so sometimes subscriptions would receive an update, even though for its specific WHERE clauses it would logically not have changed data. E.g. if you alter a specific users info on a Users table, all subscribed users would get an update.
|
||||
|
||||
You can quite easily mimic HTTP cookie sessions on whatever backend by using SocioServer hooks with SocioSession id's.
|
||||
|
||||
I cannot guarantee perfect safety of the query encryption. Neither can traditional HTTP backends. You may use SocioServer hooks to double check the incoming data yourself for your peace of mind.
|
||||
|
||||
You should be using WSS:// and HTTPS:// protocols for everything, so that the data is secure over the network. But that's easier said than done.
|
||||
|
|
@ -117,4 +115,4 @@ You should be using WSS:// and HTTPS:// protocols for everything, so that the da
|
|||
* [tRPC](https://github.com/trpc/trpc) allows you to easily build & consume fully typesafe APIs without schemas or code generation.
|
||||
|
||||
## Name:
|
||||
"Socio.js" comes from the latin verb "socio", which means to link or associate. Since this lib syncs your frontend and backend. Its also a play on words for "WebSockets" and "IO".
|
||||
"Socio.js" comes from the latin verb "socio", which means to link or associate. Since this lib syncs your frontend and backend. Its also a play on words for "WebSockets" and "IO".
|
||||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
* <a href="https://www.youtube.com/watch?v=iJIC9B3cKME&ab_channel=CepuminsLV" target="_blank">3 min video - Introduction demo.</a>
|
||||
* <a href="https://www.youtube.com/watch?v=t8_QBzk5bUk" target="_blank">16 min video - Getting started with Socio 0.7, SvelteKit, Vite.</a>
|
||||
|
||||
---
|
||||
* [Basic Demo project](https://github.com/Rolands-Laucis/Socio/blob/master/demos/basic/readme.md) - interactive bare-bones demo project.
|
||||
* [Secure Full-Stack Framework Demo project](https://github.com/Rolands-Laucis/Socio/tree/master/demos/full-stack_framework#readme) - interactive demo project with SvelteKit and Vite.
|
||||
* [Simple Documentation](https://github.com/Rolands-Laucis/Socio/blob/master/Documentation.md) - page to see direct examples and explanations of how to use various parts of the lib.
|
||||
* [Real-time rent prices in Riga, Latvia](http://riga.rolandslaucis.lv/) made by me. SvelteKit, Vite, Socio, NginX, Ubuntu server.
|
||||
|
||||
---
|
||||
No more API middleware and backend DB interfacing functions and wrappers and handlers. Write your SQL queries on the frontend and have their results be automagically refreshed on all clients when a resource is changed on the server DB. This is secure.
|
||||
|
||||
Ready for use in your small to mid sized web app 🥰 feedback is welcome.
|
||||
|
|
@ -44,7 +44,7 @@ async function QueryWrap(client: SocioSession, id: id, sql: string, params: obje
|
|||
//sanatize dynamic params!
|
||||
}
|
||||
|
||||
const socsec = new SocioSecurity({ secure_private_key: '...', logging:{verbose:true} }); //for decrypting incoming queries. This same key is used for encrypting the source files when you build and bundle them.
|
||||
const socsec = new SocioSecurity({ secure_private_key: '...', logging:{verbose:true} }); //for decrypting incoming queries. This same key is used for encrypting the source files when you build and bundle them. Same in the Vite plugin.
|
||||
const socserv = new SocioServer({ port: 3000 }, { DB_query_function: QueryWrap as QueryFunction, socio_security: socsec, logging:{verbose:true} }); //creates localhost:3000 web socket server
|
||||
```
|
||||
```ts
|
||||
|
|
@ -71,7 +71,7 @@ import { SocioSecurityVitePlugin } from 'socio/dist/secure';
|
|||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
SocioSecurityVitePlugin({ secure_private_key: 'skk#$U#Y$7643GJHKGDHJH#$K#$HLI#H$KBKDBDFKU34534', logging:{verbose:true} }),
|
||||
SocioSecurityVitePlugin({ secure_private_key: '...', logging:{verbose:true} }), //same key as in SocioSecurity
|
||||
sveltekit()
|
||||
]
|
||||
});
|
||||
|
|
@ -91,8 +91,6 @@ The use of the Socio lib **does not** prohibit the use of standard HTTP technolo
|
|||
|
||||
For SQL queries, the automagic happens because i regex parse the strings myself with simple patterns. The most basic usecases should be covered, but more complex SQL queries are not - situations like: nested queries and multiple queries in a single string. Only table names are extracted, so sometimes subscriptions would receive an update, even though for its specific WHERE clauses it would logically not have changed data. E.g. if you alter a specific users info on a Users table, all subscribed users would get an update.
|
||||
|
||||
You can quite easily mimic HTTP cookie sessions on whatever backend by using SocioServer hooks with SocioSession id's.
|
||||
|
||||
I cannot guarantee perfect safety of the query encryption. Neither can traditional HTTP backends. You may use SocioServer hooks to double check the incoming data yourself for your peace of mind.
|
||||
|
||||
You should be using WSS:// and HTTPS:// protocols for everything, so that the data is secure over the network. But that's easier said than done.
|
||||
|
|
@ -117,4 +115,4 @@ You should be using WSS:// and HTTPS:// protocols for everything, so that the da
|
|||
* [tRPC](https://github.com/trpc/trpc) allows you to easily build & consume fully typesafe APIs without schemas or code generation.
|
||||
|
||||
## Name:
|
||||
"Socio.js" comes from the latin verb "socio", which means to link or associate. Since this lib syncs your frontend and backend. Its also a play on words for "WebSockets" and "IO".
|
||||
"Socio.js" comes from the latin verb "socio", which means to link or associate. Since this lib syncs your frontend and backend. Its also a play on words for "WebSockets" and "IO".
|
||||
Loading…
Add table
Add a link
Reference in a new issue