{"id":20052577,"url":"https://github.com/devniel/node-braph","last_synced_at":"2025-06-28T18:36:52.678Z","repository":{"id":57190372,"uuid":"91710681","full_name":"devniel/node-braph","owner":"devniel","description":"The official NodeJS client for Braph.","archived":false,"fork":false,"pushed_at":"2017-10-05T01:21:42.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T04:11:25.545Z","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/devniel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-18T15:39:49.000Z","updated_at":"2017-05-18T15:40:22.000Z","dependencies_parsed_at":"2022-08-27T12:11:38.084Z","dependency_job_id":null,"html_url":"https://github.com/devniel/node-braph","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/devniel/node-braph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fnode-braph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fnode-braph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fnode-braph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fnode-braph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devniel","download_url":"https://codeload.github.com/devniel/node-braph/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devniel%2Fnode-braph/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260874252,"owners_count":23075790,"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":"2024-11-13T12:18:23.488Z","updated_at":"2025-06-28T18:36:52.661Z","avatar_url":"https://github.com/devniel.png","language":"JavaScript","readme":"# node-braph \nThe NodeJS client for Braph. With this module you can create and save your back-end entities on an on-line braph, it's intended to be used with ES6. Take this as a database as a service empowered with a braph capabilities.\n\nInstall with:\n\n    npm install braph\n\n## Usage example\n\nYou need to create an account on [Braph](http://alpha.braph.com/), currently on experimental stage, then create a braph and get the credentials along with the id. After that, you will be able to create instances from your back-end project as follows:\n\n__Braph.js__\n```js \nvar Braph  = require('braph').Braph;\n\nmodule.exports.Braph = new Braph({\n  id : 'braph_id',\n  client_id : 'client_id',\n  client_secret : 'client_secret',\n  api_url : 'https://api.braph.com/v1'\n});\n```\n\n__models/Post.js__\n```js\n\nvar Instance    = require('braph').Instance;\nvar Braph       = require(\"./../Braph\");\n\nclass Post extends Instance {\n\n    constructor(data){\n        super();\n        this.title = data.title;\n        this.content = data.content;\n        this.date = data.date;\n    }\n\n}\n\n// Required\nPost.braph = Braph;\n\n// Optional\nPost.schema = {\n    title : 'string',\n    content : 'string',\n    date :  'date'\n}\n\nmodule.exports = Post;\n\n```\n\nThe properties that will be associated with this Instance are the ones that will be returned with the __Object.getOwnPropertyNames__ method such as ___title___ or ___date___ in the example. \n\nIf you are used to work with getters as the property name using inner properties named as ____title___ or ____date___ then you have to implement the __getProperties()__ method else you will have objects with properties named as the inner ones.\n\n```js\nvar Instance    = require('braph').Instance;\nvar Braph       = require(\"./../Braph\");\n\nclass Post extends Instance {\n\n    constructor() {\n        super();\n    }\n\n    // Getters and setters.\n\n    get name(){\n        return this._name;\n    }\n\n    set name(value){\n        this._name = value;\n    }\n\n    get date(){\n        return this._date;\n    }\n\n    set date(value){\n        this._date = value;\n    }\n\n    // getProperties() implementation\n\n    getProperties() {\n        return {\n            name : this.name,\n            date : this.date\n        }\n    }\n}\n\n// Required\nPost.braph = Braph;\n\n// Optional\nPost.schema = {\n    title : 'string',\n    content : 'string',\n    date :  'date'\n}\n\nmodule.exports = Post;\n\n```\n\nNow you are able to work with **instances** of this Post pre-configured **class** and save or query them on Braph as follows:\n\n### Create instances\n\n```js\n\nvar Post = require('./models/Post.js');\n\nvar post = new Post({\n    title : 'hello world',\n    content : 'again',\n    date : new Date()\n});\n\npost.save(function(err){\n    //...\n});\n\n```\n\n### List instances\n\n```js\n\nvar Post = require('./models/Post.js');\n\nvar page = 1;\nvar itemsPerPage = 10;\n\nPost.list(page, itemsPerPage, function(err, posts){\n    //...\n});\n\n```\n\n### Read instances\n\n```js\n\nvar Post = require('./models/Post.js');\n\nvar post_id = 25;\n\nPost.read(post_id, function(err, post){\n    //...\n});\n\n```\n\n## Controllers and Middlewares\n\nThe NodeJS client for Braph provide you with the option to implement direct controllers and Braph scoped authentication to your API. It's really helpful when you want to avoid coding that controller layer that many times follows the same CRUD pattern.\n\nTo implement the **B_Auth_Token** you need to use a **Login with Braph** flow in your application where the **Authentication** middleware is required.\n\n```js\n\nvar express = require('express');\nvar cors = require('cors');\n\nvar Braph = require('./../Braph');\nvar Post = require(\"./../models/Post\"); \n\nconst cors_options = {\n\torigin: new RegExp(/(project\\.com)$/)\n};\n\nvar v1 = express.Router();\n\nmodule.exports = function (server) {\n\n\tserver.use(cors(cors_options));\n\n\tserver.options('*', cors(cors_options))\n\n\tv1.post('/auth/login',\tBraph.Authentication.login);\n\n\tv1.post(\"/posts\",       Braph.Middleware.B_Auth_Token, Post.Controller.create.bind(Post.Controller));\n\n\tv1.get(\"/posts\",        Post.Controller.list.bind(Post.Controller));\n\n\tv1.get(\"/posts/:id\",\tPost.Controller.read.bind(Post.Controller));\n\n\tserver.use('/v1', v1);\n\n\treturn server;\n\n}\n\n```\n\n\nNOTE : This module was created with the [npm-module-boilerplate](https://github.com/Travelport-Ukraine/npm-module-boilerplate).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevniel%2Fnode-braph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevniel%2Fnode-braph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevniel%2Fnode-braph/lists"}