{"id":24862052,"url":"https://github.com/evozonjs/api-sentinel","last_synced_at":"2025-10-10T09:01:57.646Z","repository":{"id":57181925,"uuid":"85310564","full_name":"evozonjs/api-sentinel","owner":"evozonjs","description":"JS layer between back-end and front-end","archived":false,"fork":false,"pushed_at":"2017-03-20T14:45:24.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-06T09:20:51.464Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evozonjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-17T12:43:07.000Z","updated_at":"2017-03-20T12:50:15.000Z","dependencies_parsed_at":"2022-09-14T04:41:24.010Z","dependency_job_id":null,"html_url":"https://github.com/evozonjs/api-sentinel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evozonjs%2Fapi-sentinel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evozonjs%2Fapi-sentinel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evozonjs%2Fapi-sentinel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evozonjs%2Fapi-sentinel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evozonjs","download_url":"https://codeload.github.com/evozonjs/api-sentinel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245699263,"owners_count":20657987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-31T22:21:41.371Z","updated_at":"2025-10-10T09:01:57.640Z","avatar_url":"https://github.com/evozonjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/version-v0.2.1-brightgreen.svg\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/tests-6/6-orange.svg\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\"\u003e\n\u003c/p\u003e\n\n# api-sentinel\na JS layer between back-end and front-end \n\n### Info\nIt's a JS layer between back-end and front-end that converts private objects (from server) to public ones (for front-end) and vice-versa, using predefined schemas. For every entity that is transmitted to/from server, there are 2 files (descriptors) containing JSON schemas that describe it.\n\nOne is public (used by the front-end developers) and describes how the entity should be transmitted to server. It also contains validators.\n\nThe other is private (only the back-end developers should have access to it) and describes what part of the entity is public or not. It also maps fields to DB fields, and has decorators defined.\n\n### Example of public descriptor:\n```javascript\n// file name: entities/test.js\nconst helpers = {\n  parseTestArray: function testArray(item){\n    return item.length \u003e 2\n  }\n}\nconst model = {\n  Text1: {\n    _type: 'string',\n    _mandatory: true,\n    _validate: '.{6,}$',\n  },\n  Array1: {\n    _type: 'array',\n    _itemType: 'boolean',\n    _validate: helpers.testArray,\n  },\n}\nmodule.exports = model;\n```\n\n**In this example:**\n\n_Text1_\n+ has to be a string\n+ it is mandatory\n+ it has to validate against a regEx.\n\n_Array1_\n+ has to be an array\n+ the items from array must be of type boolean\n+ it is not mandatory (by default mandatory == false if missing - throws warning)\n+ the array must validate against testArray function\n\n\n### Example or private descriptor:\n```javascript\n// file name: entities-private/test.js\nconst helpers = {\n  upperText: function(item){\n    return item.toUpperCase();\n  }\n}\nconst model = {\n  Text1: {\n    _public: true,\n    _decorator: helpers.upperText,\n    _privateName: 'text1'\n  },\n  Array1: {\n    _public: false,\n    _privateName: 'array1'\n  },\n}\nmodule.exports = model;\n```\n\n**In this example:**\n\n_Text1_\n+ is public (it is exposed to front-end)\n+ it has a decorator\n+ it's DB field is 'text1'\n\n_Array1_\n+ is public (it is exposed to front-end)\n+ it's DB field is 'array1'\n\n### Usage examples\n\nExample: prepare private object (from server) for front-end\n```javascript\nlet testPrivateObj = {text1: 'abcdef', array1: [true, false, false]}\n\nlet privateObj = new privateEntity('test', testPrivateObj);\n// 'test' - entity name (the file name of the entity descriptor)\n\nconsole.log(privateObj.makePublic());\n// will print: {Text1: 'ABCDEF', Array1: [true, false, false]}\n```\n\nExample: prepare public object (received from front-end) for server manipulation\n```javascript\nlet testPublicObj = {Text1: 'abcdef', Array1: [true, false, false]}\n\nlet publicObj = new publicEntity('test', testPublicObj);\n// 'test' - entity name (the file name of the entity descriptor)\n\nconsole.log(publicEntity.makePrivate());\n// will print: {text1: 'abcdef', array1: [true, false, false]}\n```\n\n### License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevozonjs%2Fapi-sentinel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevozonjs%2Fapi-sentinel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevozonjs%2Fapi-sentinel/lists"}