update
This commit is contained in:
59
api/routes/notifications.js
Normal file
59
api/routes/notifications.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const express = require("express");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
|
||||
// Classes
|
||||
const Pagans = require("../models/Notifications.js");
|
||||
|
||||
// Middlewares
|
||||
const checkHeaders = require("../middlewares/checkHeaders");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
* Get form data and send notification to user by email, sms, alert
|
||||
* @api{post}/messageanonymous
|
||||
* @apiName Notification
|
||||
* @apiDescription Send information as anonymous to tribe's druid
|
||||
* @apiGroup apxtrib
|
||||
*
|
||||
* @apiUse apxHeader
|
||||
* @apiParam {string} objectname Mandatory
|
||||
* @apiParam {String} indexname Mandatory if in conf.nationObjects then file is into nationchains/ else in /nationchains/tribes/xtribe/objectname/idx/indexname indexname contains the ObjectName .*_ (before the first _)
|
||||
*
|
||||
*
|
||||
* @apiError {json} objectNotfound the file does not exist
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 404 Not Found
|
||||
{"status":404,"ref":"Odmdb","msg":"pathnamedoesnotexist","data":{indexpath}}
|
||||
*
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"indexexist", "data":{indexname,content:{index file}}
|
||||
*
|
||||
*
|
||||
**/
|
||||
router.get("/alias/:alias", (req, res) => {
|
||||
const getalias = Pagans.getalias(req.params.alias);
|
||||
res.status(getalias.status).send(getalias);
|
||||
});
|
||||
/**
|
||||
* Remove serveur token
|
||||
* @api {get} /pagans/logout
|
||||
* @apiName Remove token
|
||||
* @apiGroup Pagans
|
||||
*
|
||||
*/
|
||||
router.get("/logout", checkHeaders, isAuthenticated, (req, res) => {
|
||||
console.log(req.session.header);
|
||||
const logout = Pagans.logout(
|
||||
req.session.header.xalias,
|
||||
req.session.header.xtribe,
|
||||
req.session.header.xdays,
|
||||
req.session.header.xhash
|
||||
);
|
||||
res.status(logout.status).json(logout);
|
||||
});
|
||||
module.exports=router;
|
@@ -9,162 +9,166 @@ const checkHeaders = require("../middlewares/checkHeaders");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/rebuildidx/:objectname
|
||||
* @apiName Rebuild all index for an object
|
||||
|
||||
/**
|
||||
* @api{get}/odmdb/idx/:objectname/:indexname - index Get
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getIndex
|
||||
* @apiDescription Get index file for an object
|
||||
*
|
||||
* @apiUse apxHeader
|
||||
* @objectname {string} Mandatory
|
||||
* @apiParam {string} objectname If in conf.nationObjects then object is into nationchains/ else in tribes/xtribe/objectname/idx/indexname indexname
|
||||
* @apiParam {String} indexname name of index file in /idx/indexnamme.json
|
||||
*
|
||||
* @apiError (404) {string} status the file does not exist
|
||||
* @apiError (404) {string} ref objectmodel to get in the right language
|
||||
* @apiError (404) {string} msg key to get template from objectmodel
|
||||
* @apiError (404) {object} data use to render lg/objectmodel_lg.json
|
||||
*
|
||||
* @apiError {json} objectNotfound the file does not exist
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 404 Not Found
|
||||
{"status":404,"ref":"Odmdb","msg":"pathnamedoesnotexist","data":{indexpath}}
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains indexfile requested
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"indexexist", "data":{indexname,content:{index file}}
|
||||
*
|
||||
*
|
||||
*/
|
||||
router.get(
|
||||
"/rebuildidx/:objectname",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
console.log("reindex");
|
||||
// check validity and accessright
|
||||
const objectPathname = conf.api.nationObjects.includes(
|
||||
req.params.objectname
|
||||
)
|
||||
? `${conf.dirapi}/nationchains/${req.params.objectname}`
|
||||
: `${conf.dirtown}/tribes/${req.session.header.xtribe}/${req.params.objectname}`;
|
||||
//console.log(objectPathname);
|
||||
if (!fs.existsSync(objectPathname)) {
|
||||
res.status(404).json({
|
||||
status: 404,
|
||||
ref: "Odmdb",
|
||||
msg: "pathnamedoesnotexist",
|
||||
data: { indexpath: objectPathname },
|
||||
});
|
||||
return false;
|
||||
router.get(
|
||||
"/idx/:objectname/:indexname",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
console.log("passe");
|
||||
// indexname = objectname_key_value.json
|
||||
let objectLocation = "../../nationchains/";
|
||||
if (!conf.api.nationObjects.includes(req.params.objectname)) {
|
||||
objectLocation += `tribes/${req.session.headers.xtribe}/`;
|
||||
// check if accessright
|
||||
}
|
||||
const indexpath = `${objectLocation}/${req.params.objectname}/idx/${req.params.indexname}`;
|
||||
if (fs.existsSync(indexpath)) {
|
||||
res
|
||||
.status(200)
|
||||
.json({
|
||||
ref: "Odmdb",
|
||||
msg: "indexexist",
|
||||
data: {
|
||||
indexname: req.params.indexname,
|
||||
content: fs.readJsonSync(indexpath),
|
||||
},
|
||||
});
|
||||
} else {
|
||||
res.status(404).json({
|
||||
ref: "Odmdb",
|
||||
msg: "pathnamedoesnotexist",
|
||||
data: { indexpath },
|
||||
});
|
||||
}
|
||||
}
|
||||
if (
|
||||
conf.api.nationObjects.includes(req.params.objectname) &&
|
||||
!req.session.header.xprofils.includes("mayor")
|
||||
) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
ref: "Odmdb",
|
||||
msg: "profilnotallow",
|
||||
data: { profils: "mayor" },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
!conf.api.nationObjects.includes(req.params.objectname) &&
|
||||
!req.session.header.xprofils.includes("druid")
|
||||
) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
ref: "Odmdb",
|
||||
msg: "profilnotallow",
|
||||
data: { profils: "druid" },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
const reindex = Odmdb.idxfromitm(objectPathname, "I", {}, {}, [], {});
|
||||
res.status(reindex.status).json(reindex);
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/idx/:indexname
|
||||
* @apiName Get index file for an object
|
||||
* @api {get} /odmdb/rebuildidx/:objectname - index refresh all
|
||||
* @apiGroup Odmdb
|
||||
* @apiName refreshAllIndex
|
||||
* @apiDescription Rebuild all index for an object, this can be usefull in case crash or any data conflict.
|
||||
*
|
||||
* @apiUse apxHeader
|
||||
* @objectname {string} Mandatory
|
||||
* @apiParam {String} indexname Mandatory if in conf.nationObjects then file is into nationchains/ else in /nationchains/tribes/xtribe/objectname/idx/indexname indexname contains the ObjectName .*_ (before the first _)
|
||||
* @apiParam {string} objectname Mandatory
|
||||
*
|
||||
* @apiError (404) {string} status the file does not exist
|
||||
* @apiError (404) {string} ref objectmodel to get in the right language
|
||||
* @apiError (404) {string} msg key to get template from objectmodel
|
||||
* @apiError (404) {object} data use to render lg/objectmodel_lg.json
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"successreindex", "data":{"indexlist":[]}}
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains indexfile requested
|
||||
* @apiError {json} objectNotfound the file does not exist
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 404 Not Found
|
||||
{"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
|
||||
*
|
||||
*/
|
||||
router.get(
|
||||
"/:objectname/idx/:indexname",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
console.log("passe");
|
||||
// indexname = objectname_key_value.json
|
||||
let objectLocation = "../../nationchains/";
|
||||
if (!conf.api.nationObjects.includes(req.params.objectname)) {
|
||||
objectLocation += `tribes/${req.session.headers.xtribe}/`;
|
||||
// check if accessright
|
||||
router.get(
|
||||
"/rebuildidx/:objectname",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
console.log("reindex");
|
||||
// check validity and accessright
|
||||
const objectPathname = conf.api.nationObjects.includes(
|
||||
req.params.objectname
|
||||
)
|
||||
? `${conf.dirapi}/nationchains/${req.params.objectname}`
|
||||
: `${conf.dirtown}/tribes/${req.session.header.xtribe}/${req.params.objectname}`;
|
||||
//console.log(objectPathname);
|
||||
if (!fs.existsSync(objectPathname)) {
|
||||
res.status(404).json({
|
||||
status: 404,
|
||||
ref: "Odmdb",
|
||||
msg: "pathnamedoesnotexist",
|
||||
data: { indexpath: objectPathname },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
conf.api.nationObjects.includes(req.params.objectname) &&
|
||||
!req.session.header.xprofils.includes("mayor")
|
||||
) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
ref: "Odmdb",
|
||||
msg: "profilnotallow",
|
||||
data: { profils: "mayor" },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
!conf.api.nationObjects.includes(req.params.objectname) &&
|
||||
!req.session.header.xprofils.includes("druid")
|
||||
) {
|
||||
res.status(403).json({
|
||||
status: 403,
|
||||
ref: "Odmdb",
|
||||
msg: "profilnotallow",
|
||||
data: { profils: "druid" },
|
||||
});
|
||||
return false;
|
||||
}
|
||||
const reindex = Odmdb.idxfromitm(objectPathname, "I", {}, {}, [], {});
|
||||
res.status(reindex.status).json(reindex);
|
||||
}
|
||||
const indexpath = `${objectLocation}/${req.params.objectname}/idx/${req.params.indexname}`;
|
||||
if (fs.existsSync(indexpath)) {
|
||||
res.status(200).json({ data: fs.readJsonSync(indexpath) });
|
||||
} else {
|
||||
res.status(404).json({
|
||||
ref: "Odmdb",
|
||||
msg: "objectfiledoesnotexist",
|
||||
data: { indexpath },
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/itm/:objectname/:primaryindex
|
||||
* @apiName Get index file for an object
|
||||
* @api {post} /odmdb/itm/:objectname - item Create
|
||||
* @apiGroup Odmdb
|
||||
*
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* @apiParam {String} objectname name Mandatory if in conf.nationObjects then file is into nationchains/ else in /nationchains/tribes/xtribe/objectname
|
||||
* @apiParam {String} primaryindex the unique id where item is store
|
||||
* @apiError (404) {string} status the file does not exist
|
||||
* @apiError (404) {string} ref objectmodel to get in the right language
|
||||
* @apiError (404) {string} msg key to get template from objectmodel
|
||||
* @apiError (404) {object} data use to render lg/objectmodel_lg.json
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains indexfile requested
|
||||
* @apiName postItm
|
||||
* @apiPermission none
|
||||
* @apiDescription Add an new item (data) into a collection of objectname items. Before Check data integrity with the relevant schema.
|
||||
* Then create a new primarykey. For multilanguage return see nationchains/model/lg/Odmdb_xx.json.
|
||||
*
|
||||
* @apiParam {string} objectname Place where to create new item, schema and version are available in /objectname/conf.json
|
||||
*
|
||||
* @apiBody {Object} data must pass Checkjson.js with schema
|
||||
*
|
||||
* @apiSuccess {json} data idxprimary Value of idxprimary into objectname collection
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"cudsuccessfull", "data":{"itm":{}}}
|
||||
*
|
||||
* @apiError {json} schemanotfound The objectname schema is not found
|
||||
* @apiError {json} pathnamedoesnotexist The objectname does not exist for the tribe
|
||||
* @apiError {json} missingprimarykey Body data must have primarykey to be created
|
||||
* @apiError {json} unconsistencyapxidx some Body data get unique key that already exist
|
||||
* @apiError {json} checkjsonfalse The body data are not consistent with the schema
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
|
||||
*
|
||||
*/
|
||||
// indexname = objectname_key_value.json
|
||||
router.get(
|
||||
"/:objectname/itm/:primaryindex",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
const objectName = req.params.objectname;
|
||||
const objectId = req.params.primaryindex;
|
||||
let objectLocation = "../../nationchains/";
|
||||
if (!conf.api.nationObjects.includes(objectName)) {
|
||||
objectLocation += `tribes/${req.session.headers.xtribe}/${objectName}`;
|
||||
// check if accessright on object on item
|
||||
// in case not res.status(403)
|
||||
}
|
||||
const objectpath = `${objectLocation}/${objectName}/itm/${objectId}`;
|
||||
|
||||
if (fs.existsSync(objectpath)) {
|
||||
res.status(200).json({ data: fs.readJsonSync(objectpath) });
|
||||
} else {
|
||||
res.status(404).json({
|
||||
ref: "Odmdb",
|
||||
msg: "objectfiledoesnotexist",
|
||||
data: { objectpath },
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
router.post(":objectname/itm", checkHeaders, isAuthenticated, (req, res) => {
|
||||
router.post("/itm/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
// Create an item of an object with no specificities
|
||||
// if specificities then create a route / model that import odmdb
|
||||
res.json({})
|
||||
});
|
||||
router.get(
|
||||
"/searchitems/:objectname/:question",
|
||||
@@ -194,22 +198,156 @@ router.get(
|
||||
);
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/schema/:objectname
|
||||
* @apiName GetSchema
|
||||
* @api {get} /odmdb/itm/:objectname/:primaryindex - item Get
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getItemFromId
|
||||
* @apiDescription Get itm for a primaryid of an object
|
||||
*
|
||||
* @apiUse apxHeader
|
||||
* @apiParam {String} objectname name Mandatory if in conf.nationObjects then file is into nationchains/ else in /nationchains/tribes/xtribe/objectname
|
||||
* @apiParam {String} primaryindex the unique id where item is store
|
||||
*
|
||||
* @apiParam {String} objectname Mandatory if headers.xworkon == nationchains then into ./nationchains/ else into ./tribes/xworkon/
|
||||
* @apiError {json} objectNotfound the file item does not exist
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {"status":404,"ref":"Odmdb","msg":"doesnotexist","data":{"objectname":"objectname","key":"apxid","val":"primaryindex"}}
|
||||
*
|
||||
* @apiError (404) {string} status a key word to understand not found schema
|
||||
* @apiError (404) {string} ref objectmodel to get in the right language
|
||||
* @apiError (404) {string} msg key to get template from objectmodel
|
||||
* @apiError (404) {object} data use to render lg/objectmodel_lg.json
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"indexexist", "data":{"indexname","content":{itm file}}
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains schema requested
|
||||
*
|
||||
*/
|
||||
// indexname = objectname_key_value.json
|
||||
router.get(
|
||||
"/itm/:objectname/:primaryindex",
|
||||
checkHeaders,
|
||||
isAuthenticated,
|
||||
(req, res) => {
|
||||
const objectName = req.params.objectname;
|
||||
const objectId = req.params.primaryindex;
|
||||
let objectLocation = "../../nationchains/";
|
||||
if (!conf.api.nationObjects.includes(objectName)) {
|
||||
objectLocation += `tribes/${req.session.headers.xtribe}/${objectName}`;
|
||||
// check if accessright on object on item
|
||||
// in case not res.status(403)
|
||||
}
|
||||
const objectpath = `${objectLocation}/${objectName}/itm/${objectId}`;
|
||||
|
||||
if (fs.existsSync(objectpath)) {
|
||||
res.status(200).json({ data: fs.readJsonSync(objectpath) });
|
||||
} else {
|
||||
res.status(404).json({
|
||||
ref: "Odmdb",
|
||||
msg: "objectfiledoesnotexist",
|
||||
data: { objectpath },
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
/**
|
||||
* @api {get} https://wall-ants.ndda.fr/Checkjson.js - schema check data lib
|
||||
* @apiGroup Odmdb
|
||||
* @apiName checkjsonjs
|
||||
* @apiDescription Public js lib to import in a browser by :<br>
|
||||
* ```<script src="wall-ants.ndda.fr/nationchains/contracts/Checkjson.js"></script>```
|
||||
* to import in a node.js:<br>
|
||||
* ```const Checkjson = require(`Checkjson.js`);```
|
||||
*
|
||||
* with functions:<br>
|
||||
* <strong>Checkjson.schema.validation(schema)</strong> that return<br>
|
||||
* - {status:200, ref:"Checkjson", msg:"validcheck"} => all rules are correct<br>
|
||||
* - {status:406, multimsg:[{ref:"Checkjson",msg:"errorkey",data:{}}]}<br>
|
||||
*
|
||||
* <strong>Checkjson.schema.data(schema{json},data{json},withschemacheck{boolean})</strong> that return<br>
|
||||
* - {status:200, ref:"Checkjson", msg:"validcheck"} => all data keys respect schema rules <br>
|
||||
* - {status:417, multimsg:[{ref:"Checkjson",msg:"errorkey",data:{}}]}<br>
|
||||
*
|
||||
* To identify issues, get the language errorkey list with a get
|
||||
* https://wall-ants.ndda.fr/nationchains/models/Checkjson_lg.json
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} https://wall-ants.ndda.fr/nationchains/schema/:objectname - schema Get public
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getPublicSchema
|
||||
* @apiDescription Get a Schema model from public apxtrib (nations, pagans,persons,towns, tribes,wwws)
|
||||
* @apiSuccess {json} contain json file
|
||||
* @apiSuccessExample {json} Fichier direct
|
||||
* HTTP/1.1 200 Success-response:
|
||||
{
|
||||
"$id": "https://smatchit.io/schema/pagan",
|
||||
"$comment": "To create account bin apxtrib",
|
||||
"title": "Pagans identity",
|
||||
"description": "A numeric id in the nationchains world",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"publickey": {
|
||||
"title": "Alias's publickey",
|
||||
"description": "Public key generate with openpgp.js",
|
||||
"type": "string",
|
||||
"format": "pgppublickey"
|
||||
},
|
||||
"alias": {
|
||||
"title": "Alias",
|
||||
"description": "text to remember easily a public key",
|
||||
"type": "string",
|
||||
"minLength": 4,
|
||||
"pattern": "^[a-z0-9]*$"
|
||||
},
|
||||
"dt_delete": {
|
||||
"title": "Date of death",
|
||||
"description": "Date of alias delete request, your will will be apply",
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"will": {
|
||||
"title": "Will script after death",
|
||||
"description": "This will script will be apply on your data 30 days after your death",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["publickey", "alias"],
|
||||
"apxid": "alias",
|
||||
"apxuniquekey": ["publickey"],
|
||||
"apxidx": [
|
||||
{ "name": "lst_alias", "keyval": "alias" },
|
||||
{ "name": "alias", "keyval": "alias" }
|
||||
],
|
||||
"apxaccessrights": {
|
||||
"owner": { "R": [], "D": [] },
|
||||
"anonymous": { "C": [], "R": ["alias"] },
|
||||
"pagan": { "R": ["alias", "publickey"] }
|
||||
}
|
||||
}
|
||||
|
||||
* @apiError {json} contain json file
|
||||
* @apiErrorExample {string} nginx html not found message
|
||||
* HTTP/1.1 404 Not Found
|
||||
* <html>...</html>
|
||||
**/
|
||||
|
||||
/**
|
||||
* @api {get} /odmdb/schema/:objectname - schema Get private
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getPrivateSchema
|
||||
* @apiDescription Get a private (profil must have accessright R on object) to a Schema model
|
||||
*
|
||||
* @apiParam {String} objectname Mandatory
|
||||
*
|
||||
* @apiError {object} ref objectmodel to get in the right language
|
||||
* @apiErrorExample {json} Error-response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {"status":404,"ref":"Odmdb","msg":"schemanotfound","data":{"fullpath"}}
|
||||
*
|
||||
* @apiSuccess {object} data contains schema requested
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 Success-response:
|
||||
* {"status":200,"data":{schema}}
|
||||
*/
|
||||
router.get("schema/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const fullpath = path.resolve(
|
||||
`${__dirname}/tribes/${req.session.header.xworkon}/schema/${req.params.pathobjectname}.json`
|
||||
@@ -219,33 +357,36 @@ router.get("schema/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
} else {
|
||||
res
|
||||
.status(404)
|
||||
.json({ msg: "schemanotfound", ref: "odmdb", data: { fullpath } });
|
||||
.json({ status:404, msg: "schemanotfound", ref: "odmdb", data: { fullpath } });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {put} /odmdb/schema/:objectname - schema Put
|
||||
* @apiGroup Odmdb
|
||||
* @apiName putSchema
|
||||
* @apiDescription Replace a schema by another one need druid profil for a tribe
|
||||
*
|
||||
* @apiParam {String} objectname Mandatory
|
||||
*
|
||||
* @apiBody {string} schemapath where to store schema .../schema
|
||||
* @apiBody {string} objectpath where to store object ...objectname/idx/conf.json
|
||||
* @apiBody {json} schema content
|
||||
* @apiBody {json} schemalang content in lg
|
||||
* @apiBody {string} lang define which schemalg is (2 letters)
|
||||
*
|
||||
* @apiError {object} ref objectmodel to get in the right language
|
||||
* @apiErrorExample {json} Error-response:
|
||||
* HTTP/1.1 404 Not Found
|
||||
* {"status":404,"ref":"Odmdb","msg":"schemanotfound","data":{"fullpath"}}
|
||||
*
|
||||
* @apiSuccess {object} data contains schema requested
|
||||
* HTTP/1.1 200 Success-response:
|
||||
* {"status":200,"data":{schema}}
|
||||
*
|
||||
*
|
||||
*/
|
||||
router.put("schema/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
/**
|
||||
* @api {put} /odmdb/schema/:objectname
|
||||
* @apiName putSchema
|
||||
* @apiGroup Odmdb
|
||||
*
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* @apiParam {String} objectname Mandatory if headers.xworkon == nationchains then into ./nationchains/ else into ./tribes/xworkon/
|
||||
* @apiBody {string} schemapath where to store schema .../schema
|
||||
* @apiBody {string} objectpath where to store object ...objectname/idx/conf.json
|
||||
* @apiBody {json} schema content
|
||||
* @apiBody {json} schemalang content in lg
|
||||
* @apiBody {string} lang define which schemalg is (2 letters)
|
||||
*
|
||||
* @apiError (404) {string} status a key word to understand not found schema
|
||||
* @apiError (404) {string} ref objectmodel to get in the right language
|
||||
* @apiError (404) {string} msg key to get template from objectmodel
|
||||
* @apiError (404) {object} data use to render lg/objectmodel_lg.json
|
||||
*
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains schema requested
|
||||
*
|
||||
*/
|
||||
const fullpath = path.resolve(
|
||||
`${__dirname}/tribes/${req.session.header.xworkon}/schema/${req.params.pathobjectname}.json`
|
||||
);
|
||||
@@ -262,4 +403,34 @@ router.put("schema/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} https://wall-ants.ndda.fr/nationchains/models/:modelname_lg.json - translation notif Get public
|
||||
* @apiGroup Odmdb
|
||||
* @apiName getPublicModelmessagekey
|
||||
* @apiDescription Get a public json object for the ref: modelname in language lg, to get a template description with key msg
|
||||
* @apiParam {string} modelname Mandatory
|
||||
* @apiSuccess {json} contain json file
|
||||
* @apiSuccessExample {json} Fichier direct
|
||||
* HTTP/1.1 200 Success-response:
|
||||
* {
|
||||
"alreadyexist": "Un object {{objectname}} avec la clé {{key}} existe déjà avec {{val}}",
|
||||
"doesnotexist": "L'object {{objectname}} avec la clé {{key}} ,'existe pas avec {{val}}",
|
||||
"getschema": "Schema {{{conf.name}}}",
|
||||
"schemanotfound": "Schema introuvable dans {{{schemaPath}}}",
|
||||
"pathnamedoesnotexist": "Le repertoire n'existe pas {{{indexpath}}}",
|
||||
"objectfiledoesnotexist": "Le fichier n'existe pas {{{objectpath}}}",
|
||||
"cudsuccessfull": "Mise à jour effectuée avec succés",
|
||||
"missingprimarykey": "Il manque une clé primaire apxid pour stocker et identifier les objects",
|
||||
"unconsistencyapxidx": "L'index {{name}} doit contenir en objkey au moins {{apxid}} car keyval n'est pas unique",
|
||||
"profilnotallow": "Vous n'avez pas le profil de {{profils}}, cette action n'est pas authorisée",
|
||||
"successreindex": "Objet reindexé à partir des items, vos index sont à jour",
|
||||
"indexexist":"L'indexe existe"
|
||||
* }
|
||||
* @apiError {json} contain json file
|
||||
* @apiErrorExample {string} nginx html not found message
|
||||
* HTTP/1.1 404 Not Found
|
||||
* <html>...</html>
|
||||
**/
|
||||
|
||||
module.exports = router;
|
||||
|
@@ -16,22 +16,40 @@ const router = express.Router();
|
||||
* Managed:
|
||||
|
||||
/**
|
||||
* @api {get} /pagans/alias/:alias
|
||||
* @apiName Is register check xalias and xhash
|
||||
* Alias exist then return public key or not
|
||||
* @api {get} /pagans/alias/:alias - alias Get
|
||||
* @apiName isalias
|
||||
* @apiGroup Pagans
|
||||
* @param {string} alias a alias that exist or not
|
||||
* @apiSuccess (200) {object} {ref:"pagans",msg:"aliasexist",data: { alias, publicKey } }
|
||||
* @apiError (404) {object} {ref:"pagans",msg:"aliasdoesnotexist",data: { alias} }
|
||||
* @apiDescription If alias exist return its publickey
|
||||
*
|
||||
* @param {string} alias
|
||||
*
|
||||
* @apiError {json} aliasdoesnotexist
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 404 Not Found
|
||||
{"status":404,"ref":"pagans","msg":"aliasdoesnotexist","data": { alias}}
|
||||
*
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, ref:"pagans","msg":"aliasexist","data": { alias, publicKey }}
|
||||
* *
|
||||
**/
|
||||
router.get("/alias/:alias", (req, res) => {
|
||||
const getalias = Pagans.getalias(req.params.alias);
|
||||
res.status(getalias.status).send(getalias);
|
||||
});
|
||||
/**
|
||||
* @api {get} /pagans/logout
|
||||
* @apiName Remove token
|
||||
* Remove serveur token
|
||||
* @api {get} /pagans/logout - pagan Logout
|
||||
* @apiName Removetoken
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription Remove token
|
||||
*
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {status: 200, ref: "Pagans", msg: "logout"
|
||||
*
|
||||
*/
|
||||
router.get("/logout", checkHeaders, isAuthenticated, (req, res) => {
|
||||
@@ -44,41 +62,20 @@ router.get("/logout", checkHeaders, isAuthenticated, (req, res) => {
|
||||
);
|
||||
res.status(logout.status).json(logout);
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {get} /pagans/person:alias
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @api {get} /pagans/isauth - pagan isAuthenticated?
|
||||
* @apiName isAuth
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
* @param {string} alias that exist
|
||||
* @param {string} tribeId that exist with a person alias
|
||||
* @apiSuccess (200) {ref:"pagans",msg:"personexist",data: { person } }
|
||||
* @apiError (404) {ref:"pagans",msg:"persondoesnotexist",data: { person } }
|
||||
* @apiDescription Check if pagan's token is still valid
|
||||
*
|
||||
* @todo check accessright for req.session.header.xalias to see if jhe can get person data
|
||||
* if req.param.alias == req.session.header.xalias => Owner
|
||||
* else need accessright to on person set at R
|
||||
* */
|
||||
router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const getperson = Pagans.getperson(
|
||||
req.session.header.xtribe,
|
||||
req.params.alias,
|
||||
{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias }
|
||||
);
|
||||
res.status(getperson.status).send(getperson);
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {get} /pagans/isauth
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
* @apiError (400) missingheaders
|
||||
* @apiError (400) xaliasdoesnotexist
|
||||
* @apiError (400) signaturefailled
|
||||
* @apiError (401) aliasanonymous
|
||||
* @apiError (404) tribedoesnotexist
|
||||
*
|
||||
* @apiError (400) {object} status missingheaders / xalias does not exist / signaturefailled
|
||||
* @apiError (401) {object} alias anonymous (not authenticated)
|
||||
* @apiError (404) {string} tribe does not exist
|
||||
*
|
||||
* @apiSuccess (200) {object} data contains indexfile requested
|
||||
* @apiSuccess (200) valid
|
||||
* {object} data contains indexfile requested
|
||||
*
|
||||
*/
|
||||
router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
|
||||
@@ -94,17 +91,27 @@ router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {post} /pagans
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @api {post} /pagans - pagan Post
|
||||
* @apiName addpagan
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* Create a pagan account from alias, publickey, if trusted recovery =>
|
||||
* @apiDescription
|
||||
* Create a pagan account from alias, publickey, if trusted recovery =>
|
||||
* Create a person in xtribe/person/xalias.json with profil.auth={email,privatekey, passphrase}
|
||||
* Middleware isAuthenticated check that:
|
||||
* Middleware isAuthenticated check that:
|
||||
* - xhash is well signed from private key linked to the publickey of alias
|
||||
* - check that alias does not already exist (if yes then verifiedsigne would be false)
|
||||
* Need to wait next block chain to be sure that alias is register in the blokchain
|
||||
*
|
||||
* @apiError {json} objectNotfound the file does not exist
|
||||
* @apiErrorExample {json}
|
||||
* HTTP/1.1 404 Not Found
|
||||
{"status":404,"ref":"Odmdb","msg":"pathnamedoesnotexist","data":{indexpath}}
|
||||
*
|
||||
* @apiSuccess {object} indexfile content
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
* HTTP/1.1 200 OK
|
||||
* {"status":200, "ref":"Odmdb", "msg":"indexexist", "data":{indexname,content:{index file}}
|
||||
*
|
||||
*/
|
||||
router.post("/", checkHeaders, isAuthenticated, (req, res) => {
|
||||
//console.log("pass ici", req.body);
|
||||
@@ -150,12 +157,61 @@ router.post("/", checkHeaders, isAuthenticated, (req, res) => {
|
||||
}
|
||||
});
|
||||
/**
|
||||
* @api {post} /pagans/person
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @api {delete} /pagans/alias/:alias - pagan Delete
|
||||
* @apiName deletepagan
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription
|
||||
* Delete an alias and his publickey
|
||||
* */
|
||||
router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
|
||||
const result = Pagans.deletealias(req.params.id, req.session.header);
|
||||
res.status(result.status).send(result.data);
|
||||
});
|
||||
router.delete("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
|
||||
const result = Pagans.deleteperson(req.params.id, req.session.header);
|
||||
res.status(result.status).send(result.data);
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {get} /pagans/person:alias - person Get
|
||||
* @apiName getpersondata
|
||||
* @apiDescription Get person information from his alias for a xtribe (data and profils per apps)
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* @apiParam {string} alias
|
||||
*
|
||||
* @apiSuccess (200) personExist
|
||||
* @apiSuccessExample {json}
|
||||
* {status:200, ref:"pagans",msg:"personexist",data: { person } }
|
||||
*
|
||||
* @apiError (404) Notfound
|
||||
* @apiErrorExample {json}
|
||||
* {status: 404, ref:"pagans",msg:"persondoesnotexist",data: { person } }
|
||||
*
|
||||
* @todo check accessright for req.session.header.xalias to see if jhe can get person data
|
||||
* if req.param.alias == req.session.header.xalias => Owner
|
||||
* else need accessright to on person set at R
|
||||
* */
|
||||
router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
const getperson = Pagans.getperson(
|
||||
req.session.header.xtribe,
|
||||
req.params.alias,
|
||||
{ xprofils: req.session.header.xprofils, xalias: req.session.header.xalias }
|
||||
);
|
||||
res.status(getperson.status).send(getperson);
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {post} /pagans/person - person Post
|
||||
* @apiName addperson
|
||||
* @apiGroup Pagans
|
||||
* @apiDescription
|
||||
* add a person = alias + tribe with specific accessright and specific schema link to tribe
|
||||
*
|
||||
*
|
||||
*
|
||||
* @todo add tribe/schema/person.json
|
||||
*/
|
||||
router.post("/person", checkHeaders, isAuthenticated, (req, res) => {
|
||||
@@ -170,13 +226,13 @@ router.post("/person", checkHeaders, isAuthenticated, (req, res) => {
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {put} /pagans/person
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @api {put} /pagans/person - person Put
|
||||
* @apiName updateperson
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
*
|
||||
* @apiDescription
|
||||
* update a person = alias + tribe with specific accessright and specific schema link to tribe
|
||||
* @todo add tribe/schema/person.json
|
||||
|
||||
* @todo add tribe/schema/person.json
|
||||
*/
|
||||
router.put("/person", checkHeaders, isAuthenticated, (req, res) => {
|
||||
//console.log(req.body);
|
||||
@@ -189,30 +245,12 @@ router.put("/person", checkHeaders, isAuthenticated, (req, res) => {
|
||||
res.status(persoup.status).json(persoup);
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {delete} /pagans/alias/:alias
|
||||
* @apiName Is register check xalias and xhash
|
||||
* @apiGroup Pagans
|
||||
* @apiUse apxHeader
|
||||
* */
|
||||
router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
|
||||
const result = Pagans.deletealias(req.params.id, req.session.header);
|
||||
res.status(result.status).send(result.data);
|
||||
});
|
||||
router.delete("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
||||
console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
|
||||
const result = Pagans.deleteperson(req.params.id, req.session.header);
|
||||
res.status(result.status).send(result.data);
|
||||
});
|
||||
|
||||
/**
|
||||
* @api {get} /pagans/keyrecovery/tribe/email
|
||||
* @apiName apxtrib
|
||||
* @api {get} /pagans/keyrecovery/tribe/email - recovery key by email
|
||||
* @apiName recoveryKey
|
||||
* @apiGroup Pagans
|
||||
*
|
||||
*
|
||||
*
|
||||
* @apiError (400) {object} status missingheaders / xalias does not exist / signaturefailled
|
||||
* @apiError (401) {object} alias anonymous (not authenticated)
|
||||
* @apiError (404) {string} tribe does not exist
|
||||
|
82
api/routes/trackings.js
Normal file
82
api/routes/trackings.js
Normal file
@@ -0,0 +1,82 @@
|
||||
const express = require("express");
|
||||
const glob = require("glob");
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const conf = require(`${process.env.dirtown}/conf.json`);
|
||||
const Odmdb = require("../models/Odmdb.js");
|
||||
// Middlewares
|
||||
const checkHeaders = require("../middlewares/checkHeaders");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
/**
|
||||
* @api {get} https://dns.xx/trk/pathtofile? - tracking system
|
||||
* @apiGroup Trackings
|
||||
* @apiName trackingsystem
|
||||
* @apiDescription
|
||||
* without header:<br>
|
||||
* <code>https://dns.xx/trk/pathtofile?alias=anonymous&uuid=1b506f71-1bff-416c-9057-cb8b86296f60&src=btnregister&version=1&lg=fr </code>
|
||||
*
|
||||
* with header<br>
|
||||
* <code>https://dns.xx/trk/pathtofile?srckey=btnregister&version=1</code>
|
||||
*
|
||||
* where pathtofile is a ressource accessible from https://dns.xx/pathtofile
|
||||
* html usage to track a loading page or email when a picture is load
|
||||
* using apxwebapp in /src/ we got:
|
||||
* <code> < img src="static/img/photo.jpg" data-trksrckey="loadpage" data-version="1" > </code>
|
||||
*
|
||||
* using html + apx.js (or at least with header {xalias,xuuid,xlang})
|
||||
* <code>< img lazysrc="trk/static/img/photo.jpg data-trksrckey="loadpage" data-version="1" ></code>
|
||||
*
|
||||
* in js action:
|
||||
*
|
||||
* <code>
|
||||
* <button></button>
|
||||
* <a data-trksrckey="linktoblabla" href='https:..'
|
||||
* onclick="apx.trackvisit("btnaction",1);actionfct();">
|
||||
* </a>
|
||||
* </code>
|
||||
* #will hit an eventlistener<br>
|
||||
* <code> axios.get("https://dns.xx/trk/cdn/empty.json?alias=anonymous&uuid=1b506f71-1bff-416c-9057-cb8b86296f60&srckey=btnregister&version=1");
|
||||
* </code>
|
||||
*
|
||||
* #or if no js available (example:email or pdf document)<br>
|
||||
* <code> < img src="https://dns.xx/trk/static/img/photo.jpg?alias=anonymous&uuid=1b506f71-1bff-416c-9057-cb8b86296f60&srckey=loadpage&version=1"</code>
|
||||
*
|
||||
* <code>
|
||||
* <a href="https://dns.xx/trk/redirect?alias=anonymous&uuid=1b506f71-1bff-416c-9057-cb8b86296f60&srckey=loadpage&version=1&url=http://..."
|
||||
* </code>
|
||||
*
|
||||
* will hit a tracker then redirect to url></a> *
|
||||
*
|
||||
*
|
||||
*
|
||||
* **if you use apx.js** : in html add in < button >, < img >, < a > tag data-trksrc="srckey"
|
||||
* <code>
|
||||
* < img src="https://dns.xx/static/img/photo.jpg" data-trkversion="1" data-trksrckey="registerform">
|
||||
* < button data-trksrc="https://dns.xx/static/img/photo.jpg" data-trkversion="1" data-trksrckey="registerform">
|
||||
* </code>
|
||||
*
|
||||
* Tracking log are store into tribe/logs/nginx/tribe_appname.trk.log
|
||||
* Src have to be manage in tribe/api/models/lg/src_en.json
|
||||
* <code>{"srckey":{
|
||||
* "app":"presentation|app|apptest",
|
||||
* "title":"",
|
||||
* "description":""
|
||||
* }
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @apiParam {String} alias=anonymous if authenticated we get from headers
|
||||
* @apiParam {String} uuid a uuid v4 generate the first time a web page is open on a browser
|
||||
* @apiParam {String} srckey source action that trig this get
|
||||
* @apiParam {integer} version=1 can be an int, date or any version of the src
|
||||
* @apiParam {integer} [tm] a timestamp of action when it is not immediate (for offline app)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports=router;
|
@@ -8,6 +8,7 @@ const checkHeaders = require("../middlewares/checkHeaders");
|
||||
const isAuthenticated = require("../middlewares/isAuthenticated");
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
* To manage an nginx conf
|
||||
*
|
||||
|
Reference in New Issue
Block a user