1
0
forked from apxtri/apxtri
apxtri/middlewares/header.md

123 lines
5.4 KiB
Markdown
Raw Permalink Normal View History

2023-12-07 12:04:19 +01:00
## api users and backend developers
api documentation for routes and middleware has to respect apidoc's rules [https://apidocjs.com/](https://apidocjs.com) 
2024-04-12 12:49:48 +02:00
To update this doc accessible in [https://wal-ants.ndda.fr/apidoc](https://wal-ants.ndda.fr/cdn/apidoc) :
2023-12-07 12:04:19 +01:00
2024-04-12 12:49:48 +02:00
 `$ tribe=adminapi yarn apidoc` 
2023-12-07 12:04:19 +01:00
2024-04-12 12:49:48 +02:00
For api tribe's doc  accessible in [https://admin.smatchit.io/apidoc](https://smatchit.io/cdn/apidoc) [:](https://smatchit.io/cdn/apidoc:) 
2023-12-07 12:04:19 +01:00
2024-04-12 12:49:48 +02:00
`$ tribe=smatchit yarn apidoc`
2023-12-07 12:04:19 +01:00
2024-04-12 12:49:48 +02:00
To get overview check README.md project and the package.json [https://gitea.ndda.fr/apxtri/apxtri](https://gitea.ndda.fr/apxtri/apxtri)
2023-12-07 12:04:19 +01:00
2024-04-12 12:49:48 +02:00
A special tribe call adminapi in any towns (node), it works the same than all the other tribe except that all their data are synchronize with a blockchain 
2023-12-07 12:04:19 +01:00
2024-04-12 12:49:48 +02:00
Objects manage by adminapi are: pagans (numerique id =alias/public key / private key), notifications (cypher message betxeen alias) , nations (rules apply to all towns belonging to a nations), towns ( a server that host IT ressources disk space, ram, bandwith and rules aplly to all tribe belonging to a town), tribes (( a sharing space to store data as well as api with rules to any person that use it), wwws (web space, dns)
2023-12-07 12:04:19 +01:00
## Object management (Odmdb)
An object has a name and is defined by a schema that contain properties key.
A propertie has a name and a list of caracteristics (type, pattern,format,...) that have to be validate to be accepted.
All properties respect the rules [https://json-schema.org/draft/2020-12/schema,](https://json-schema.org/draft/2020-12/schema,) some extra"format" can be add to mutualise recurrent regex pattern
2024-04-12 12:49:48 +02:00
To access a schema [https://wall-ants.ndda.fr/api/adminapi/schema/tribename/schamname.json](https://wall-ants.ndda.fr/nationchains/schema/nations.json) and language is set by the header in xlang
2023-12-07 12:04:19 +01:00
A checkjson.js is available to manage all specific format [https://wall-ants.ndda.fr/Checkjson.js](https://wall-ants.ndda.fr/Checkjson.js) see **Odmdb - schema Checkjson**
**required**: an array of required properties
2024-04-12 12:49:48 +02:00
**Additional properties that not exist in 2020-12/schema :**
2023-12-07 12:04:19 +01:00
**apxid**: the propertie used as an unique id
**apxuniquekey**: array of unique properties
2024-04-12 12:49:48 +02:00
**apxidx** : array of index definition
2023-12-07 12:04:19 +01:00
**apxaccessrights**: object with key profilname and accessrights on properties {profilname:{C:\[properties array\],R:\[properties array\],U:\[\],D:\[\]}}
Items of an object are store in files into :  
```plaintext
2024-04-12 12:49:48 +02:00
tribename/objectnames/idx/keyval_objkey.json
tribename//objectnames/itm/uniqueid.json
```
## Accessrights:
An alias is just an identity, to access a tribe, a person must exist with an authenticated alias into /tribes/{tribename}/objects/persons/itm/{alias}.json
A person has a property profils with a list of profilename, common profiles are : anonymous (no identity) / pagan (an identity)  / person (an identity with access right into a tribe) / druid (the administrator of a tribe) / mayor (administrator of a town/server)/ and any profil can be define for a tribe
Each object has an apxaccessrights that is a list of profil and CRUD access per object key.
Example: owner on this object cab create delete an item is own, can read a list of propertie and update only some.
```plaintext
"owner": {
"C" : [],
"D": [],
"R": ["alias","owner","profils","firstname","lastname","dt_birth"],
"U": ["firstname","lastname","dt_birth"]
}
2023-12-07 12:04:19 +01:00
```
## api pre-request
2024-04-12 12:49:48 +02:00
API Endpoint url: **/api/{tribename}/{routename}/xxx**
Domaine name can be a adminapi donaim name aswell any tribe's domain  name. Check nginx conf in /tribename/nginx 
2023-12-07 12:04:19 +01:00
**Valid header see Middlewares**
2024-04-12 12:49:48 +02:00
App use openpgp.js lib to sign xalias\_xdays  (xdays a timestamp integer in miilisecond from Unix Epoch) with a privatekey and store it in xhash.
2023-12-07 12:04:19 +01:00
/middlewares/isAuthenticated.js check if (xhash) is a valid signature of the public key a xhash is valid for 24 hours
See Pagans models that contain authentification process
**api Return in 3 data structure:**
A - data file from a classical get  [https://wall-ants.ndda.fr/Checkjson.js](https://smatchit.io/Checkjson.js)
B -  a json single answer **{status, ref,msg,data}:**
2023-12-07 12:04:19 +01:00
* status: http code return
* ref: model/route name reference where message come from
* msg: a message template key store into models/lg/name\_lg.json (where lg is 2 letters language)
* data: an object data use to render the value of the message key.
C - a json multi answer **{status,multimsg:\[{ref,msg,data}\]}**
2023-12-07 12:04:19 +01:00
         Each {ref,msg,data\] work the same way than B
2024-04-03 08:58:02 +02:00
To show feedback context message in a language lg => get /api/adminapi/objects/tplstrings/{{model}}\_{{lg}}.json
2023-12-07 12:04:19 +01:00
This contain a json {msg:"mustache template string to render with data"}  
## Add tribe's api:
2024-04-12 12:49:48 +02:00
Accessible with https://dns/api/tribename/routename/
2023-12-07 12:04:19 +01:00
```plaintext
2024-04-03 08:58:02 +02:00
/tribes/tribename/apxtri/routes
/tribes/tribename/apxtri/middlewares
/tribes/tribename/apxtri/models
2024-03-15 08:49:23 +01:00
/tribes/tribename/schema
/tribes/tribename/schema/lg
2023-12-07 12:04:19 +01:00
```
```plaintext
// Example of a route
const tribe="smatchit";
const conftrib = require(`../../../adminapi/objects/tribes/itm/${tribe}.json`);
const conf = require(`../../../adminapi/objects/tribes/itm/adminapi.json`);
2024-03-15 08:49:23 +01:00
const express = require(`../../../adminapi/apxtri/node_modules/express`);
const fs = require(`../../../adminapi/apxtri/node_modules/fs-extra`);
const Nofications = require(`../../../adminapi/apxtri/models/Notifications.js`);
const Appscreens = require(`../models/Appscreens`);
const router=express.Router();
module.exports=router;
2023-12-07 12:04:19 +01:00
```