diff --git a/config/about.js b/config/about.js new file mode 100644 index 0000000..f1efa1f --- /dev/null +++ b/config/about.js @@ -0,0 +1,15 @@ +/* + This file should be customized for your app. The string in this file is + displayed when a user makes the 'about' JSON RPC call. +*/ + +module.exports = ` +This is the about string for the ipfs-service-provider repository: +https://github.com/Permissionless-Software-Foundation/ipfs-service-provider + +Brought to you by the Permissionless Software Foundation: +https://PSFoundation.cash + +Documentation: +https://ipfs-service-provider.fullstack.cash/ +` diff --git a/package-lock.json b/package-lock.json index 777b4af..5598ba0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6587,7 +6587,8 @@ }, "ini": { "version": "1.3.5", - "resolved": "", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", "optional": true }, "is-fullwidth-code-point": { @@ -6790,7 +6791,8 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "optional": true } } @@ -8677,9 +8679,9 @@ } }, "ipfs-coord": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/ipfs-coord/-/ipfs-coord-3.0.4.tgz", - "integrity": "sha512-z9c1vxR8krDGPnV97A6GrJ7o5NjpMFzoNWoQNmQdud13pO1tJbcXCvM2DVR/9m9CHs+WNht4PuC4zNF/61fXHw==", + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/ipfs-coord/-/ipfs-coord-3.0.6.tgz", + "integrity": "sha512-EmlLcYptpOztZ9aLB6DHL8vy0gsnRzvRMzBOno1jW7Ht/SP7KhhYGpXvG/8+BYRFgFhAHPHiC2CJMn9N9La4fw==", "requires": { "bch-encrypt-lib": "^2.0.0", "orbit-db": "^0.26.1" diff --git a/package.json b/package.json index 1b0a9be..a2a8d5c 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "bcryptjs": "^2.4.3", "glob": "^7.1.6", "ipfs": "^0.54.4", - "ipfs-coord": "^3.0.4", + "ipfs-coord": "^3.0.6", "jsonrpc-lite": "^2.2.0", "jsonwebtoken": "^8.5.1", "kcors": "^2.2.2", diff --git a/src/lib/ipfs.js b/src/lib/ipfs.js index 163e0c8..67df15e 100644 --- a/src/lib/ipfs.js +++ b/src/lib/ipfs.js @@ -85,7 +85,8 @@ class IPFSLib { // type: 'browser', bchjs: this.bchjs, privateLog: this.rpc.router, - isCircuitRelay: this.config.isCircuitRelay + isCircuitRelay: this.config.isCircuitRelay, + apiInfo: 'https://ipfs-service-provider.fullstack.cash/' }) await this.ipfsCoord.isReady() diff --git a/src/rpc/about/index.js b/src/rpc/about/index.js new file mode 100644 index 0000000..772382b --- /dev/null +++ b/src/rpc/about/index.js @@ -0,0 +1,45 @@ +/* + This is the JSON RPC router for the users API +*/ + +// Public npm libraries +const jsonrpc = require('jsonrpc-lite') + +// Local libraries +const aboutStr = require('../../../config/about') + +class AuthRPC { + constructor (localConfig) { + // Encapsulate dependencies + this.jsonrpc = jsonrpc + } + + /** + * @api {JSON} /about About IPFS Node + * @apiPermission public + * @apiName About + * @apiGroup JSON About + * + * @apiExample Example usage: + * {"jsonrpc":"2.0","id":"555","method":"about"} + * + * @apiDescription + * This endpoint can be customized so that users can retrieve information about + * your IPFS node and Service Provider application. This is a great place to + * put a website URL, an IPFS hash, an other basic information. + */ + + // This is the top-level router for this library. + // This is a bit different than other router libraries, because there is + // only one response, which is a string about this node. + async aboutRouter (rpcData) { + return { + success: true, + status: 200, + message: aboutStr, + endpoint: 'about' + } + } +} + +module.exports = AuthRPC diff --git a/src/rpc/auth/index.js b/src/rpc/auth/index.js index 686dd56..5fdef58 100644 --- a/src/rpc/auth/index.js +++ b/src/rpc/auth/index.js @@ -47,6 +47,16 @@ class AuthRPC { } } + /** + * @api {JSON} /auth Get JWT Token + * @apiPermission public + * @apiName AuthUser + * @apiGroup JSON Auth + * + * @apiExample Example usage: + * {"jsonrpc":"2.0","id":"556","method":"auth","params":{ "endpoint": "authUser", "login": "test555@test.com", "password": "password"}} + * + */ async authUser (rpcData) { try { // console.log('authUser rpcData: ', rpcData) diff --git a/src/rpc/index.js b/src/rpc/index.js index 4c808cf..4ebf083 100644 --- a/src/rpc/index.js +++ b/src/rpc/index.js @@ -9,6 +9,7 @@ const jsonrpc = require('jsonrpc-lite') const wlogger = require('../lib/wlogger') const UserController = require('./users') const AuthController = require('./auth') +const AboutController = require('./about') let _this @@ -18,6 +19,7 @@ class JSONRPC { this.jsonrpc = jsonrpc this.userController = new UserController() this.authController = new AuthController() + this.aboutController = new AboutController() // This will be replaced once the ipfs-coord lib finishes initializing. this.ipfsCoord = {} @@ -60,6 +62,8 @@ class JSONRPC { case 'auth': retObj = await _this.authController.authRouter(parsedData) break + case 'about': + retObj = await _this.aboutController.aboutRouter(parsedData) } // console.log('retObj: ', retObj) diff --git a/src/rpc/users/index.js b/src/rpc/users/index.js index f6ddb94..8bdb3fa 100644 --- a/src/rpc/users/index.js +++ b/src/rpc/users/index.js @@ -129,6 +129,16 @@ class UserRPC { } } + /** + * @api {JSON} /users Get all users + * @apiPermission public + * @apiName GetAllUsers + * @apiGroup JSON Users + * + * @apiExample Example usage: + * {"jsonrpc":"2.0","id":"555","method":"users","params":{ "endpoint": "getAllUsers", "apiToken": ""}} + * + */ // Get all Users. async getAll () { try { @@ -155,6 +165,16 @@ class UserRPC { } } + /** + * @api {JSON} /users Get a user + * @apiPermission public + * @apiName GetAUser + * @apiGroup JSON Users + * + * @apiExample Example usage: + * {"jsonrpc":"2.0","id":"123","method":"users","params":{ "endpoint": "getUser", "apiToken": "", "userId": "<_id>"}} + * + */ // Get a specific user. async getUser (rpcData, userModel) { try { @@ -186,6 +206,16 @@ class UserRPC { } } + /** + * @api {JSON} /users Update a user + * @apiPermission public + * @apiName UpdateAUser + * @apiGroup JSON Users + * + * @apiExample Example usage: + * {"jsonrpc":"2.0","id":"123","method":"users","params":{ "endpoint": "updateUser", "apiToken": "", "userId": "<_id>", "name": "test999"}} + * + */ async updateUser (rpcData, userModel) { try { // console.log('updateUser rpcData: ', rpcData) @@ -214,6 +244,16 @@ class UserRPC { } } + /** + * @api {JSON} /users Delete a user + * @apiPermission public + * @apiName DeleteAUser + * @apiGroup JSON Users + * + * @apiExample Example usage: + * {"jsonrpc":"2.0","id":"123","method":"users","params":{ "endpoint": "deleteUser", "userId": "<_id>", "apiToken": ""}} + * + */ async deleteUser (rpcData, userModel) { try { // console.log('deleteUser rpcData: ', rpcData)