0.0.17 • Published 1 year ago

websocket-foundation v0.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

websocket-foundation

Socket.io & mongoDB based websocket server foundation.

Permissions

Default permissions

OperationActions
Readsearch,join, leave
Writereplace, update
createcreate
deletedelete

Entities

Every entity needs a schema to pass the validation step. The Schema is based on Ajv JSON schema validator.

The SocketAccess checks whether the entities exist and create collections if they don't. MongoDB collections are never deleted when you remove existing entities.

Default entities

EntitySchema
userUserSchema
aclRoleAclRoleSchema
userAclRoleUserAclRoleSchema

Socket Access

All generated events expect an authentication. Authenticate yourself via user:login with credentials or userToken:

{
    "username": "",
    "password": ""
}
{
    "userToken": ""
}
Trigger EventResult EventError Event
user:loginuser:login:successuser:login:failed

Events

The SocketAccess will automatically generate events for your entities in combination with all of your operations and actions.

Example

You are creating a new entity document. The system will create events to communicate with the socket.

Trigger EventResult EventError EventAdditional entity room events
document:read:searchdocument:founddocument:search:error-
document:read:joinclient:update-client:joined, client:update
document:read:leave--client:leaved
document:write:replacedocument:replaceddocument:replace:errorupdated
document:write:updatedocument:updateddocument:update:errorupdated
document:create:createdocument:createddocument:create:error-
document:delete:deletedocument:deleteddocument:delete:errordeleted

Actions

search

Search for specific ids or with multiple mongoDB AND filters.

{
    "ids": [],
    "limit": 50,
    "offset": 0,
    "sort": {},
    "filter": [
        {
            "key": "active",
            "value": true
        }
    ],
    "associations": {}
}

join, leave:

Just add the specific mongoDB document _id to the payload you want to join/leave.

create:

Expects an object payload with your entity required data.

{
    "_id": "6948DF80-14BD-4E04-8842-7668D9C001F1",
    "username": "test",
    "password": "alreadyHashedPassword",
    "firstName": "firstName",
    "lastName": "lastName",
    "email": "test@example.com",
    "active": true,
    "admin": true
}

delete:

Expects an array payload with ids.

{
    "ids": [
        "6948DF80-14BD-4E04-8842-7668D9C001F1",
        "6948DF80-14BD-4E04-8842-7668D9C001F2",
        "6948DF80-14BD-4E04-8842-7668D9C001F3"
    ]
}

replace, update:

Replace is replacing the whole collection entry, update is updating specific fields. Expects an object payload with your entity update/replace required data.

0.0.16

1 year ago

0.0.17

1 year ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.15

1 year ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago