From 56318059c76620cd3d0143c1f9503541424c9e9a Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Mon, 11 Nov 2024 16:07:27 -0500 Subject: [PATCH] Initial commit --- .eslintrc.js | 7 +++ .github/workflows/main.yml | 75 ++++++++++++++++++++++++ .gitignore | 11 ++++ CHANGELOG.md | 5 ++ LICENSE.md | 115 +++++++++++++++++++++++++++++++++++++ README.md | 1 + lib/config.js | 13 +++++ lib/http.js | 14 +++++ lib/index.js | 8 +++ lib/main.js | 7 +++ package.json | 42 ++++++++++++++ test/mocha/.eslintrc | 9 +++ test/mocha/10-api.js | 7 +++ test/package.json | 31 ++++++++++ test/test.config.js | 17 ++++++ test/test.js | 12 ++++ 16 files changed, 374 insertions(+) create mode 100644 .eslintrc.js create mode 100644 .github/workflows/main.yml create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 lib/config.js create mode 100644 lib/http.js create mode 100644 lib/index.js create mode 100644 lib/main.js create mode 100644 package.json create mode 100644 test/mocha/.eslintrc create mode 100644 test/mocha/10-api.js create mode 100644 test/package.json create mode 100644 test/test.config.js create mode 100644 test/test.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..2297f74 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + root: true, + env: { + node: true + }, + extends: 'digitalbazaar' +}; diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..28e9f44 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,75 @@ +name: Bedrock Node.js CI + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: + matrix: + node-version: [14.x] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - name: Run eslint + run: npm run lint + test-node: + needs: [lint] + runs-on: ubuntu-latest + timeout-minutes: 10 + services: + mongodb: + image: mongo:4.2 + ports: + - 27017:27017 + strategy: + matrix: + node-version: [12.x, 14.x] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: | + cd test + npm install + - name: Run test with Node.js ${{ matrix.node-version }} + run: | + cd test + npm test + coverage: + needs: [test-node] + runs-on: ubuntu-latest + timeout-minutes: 10 + services: + mongodb: + image: mongo:4.2 + ports: + - 27017:27017 + strategy: + matrix: + node-version: [14.x] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: | + cd test + npm install + - name: Generate coverage report + run: | + cd test + npm run coverage-ci + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + file: ./test/coverage/lcov.info + fail_ci_if_error: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc36171 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.log +*.sw[nop] +*~ +.nyc_output +.project +.settings +.vscode +TAGS +coverage +node_modules +reports diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2fc0dad --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# bedrock-module-template-http ChangeLog + +## 1.0.0 - TBD + +- See git history for changes. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..91c3522 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,115 @@ +Bedrock Non-Commercial License v1.0 +=================================== + +Copyright (c) 2011-2021 Digital Bazaar, Inc. +All rights reserved. + +Summary +======= + +This license allows the licensee to use Bedrock and its software modules +for non-commercial purposes such as self-study, research, personal +projects, or for evaluation purposes. If the licensee uses Bedrock +directly or indirectly to generate revenue, or to provide products or +services to more than 500 people (users), the licensee must immediately +obtain a non-profit or commercial license. + +Examples +======== + +These are examples of cases that are allowed by this license: + +* The licensee is an individual that creates Bedrock-dependent software for + personal use only. +* The licensee is an individual or group of students/researchers that uses + Bedrock to experiment with an idea for a non-commercial project. +* The licensee is a startup company that prototypes a Bedrock-dependent + product before they have cash flow and will be testing the prototype + software with less than 500 users. The service will not generate revenue + of any kind. +* The licensee is a for-profit organization that creates a product or + service that is used by less than 500 users and is built with or + integrates with Bedrock. The service must be exclusively provided for free + and no parent, subsidiary, agent, or affiliate organization may profit + from its use. + +These cases require a non-profit or commercial license: + +* The licensee is a non-profit that receives funding to create and/or run a + Bedrock-dependent service. +* The licensee is a startup company with Bedrock-dependent software that is + funded by another organization. +* The licensee is a startup company that is going into production with + Bedrock-dependent software. +* The licensee has more than 500 users using a Bedrock-dependent service + either directly or indirectly. +* The licensee is a medium to large organization that builds or integrates a + commercial product or service with Bedrock. + +THE LICENSE +=========== + +This section and all subsequent sections of this document constitute the +agreement between the licensee and Digital Bazaar, Inc. + +DEFINITIONS +=========== + +* Product - The Bedrock software and any modules associated with Bedrock +where Digital Bazaar, Inc. owns the copyright. + +CONDITIONS +========== + +Redistribution and use in source and binary forms, with or without +modification, are permitted for NON-COMMERCIAL PURPOSES as long as the +following conditions are met: + +1. Any use of the Product must not generate revenue for the licensee or + any parent, subsidiary, agent, or affiliate of the licensee. Use of + Product includes, but is not limited to, interacting with any of the + licensee's Product-dependent products or services over a network. + +2. The aggregate number of individual people (users) of the licensee's + products or services that use Product must be less than 500. + +3. Redistributions of source code must retain the above copyright notice + intact, this list of conditions and the following disclaimer. + +4. Redistributions in binary form must reproduce the above copyright + notice, this license and the following disclaimer in the documentation and + on a web page available via interactive use and/or other materials + provided with the distribution. + +5. Neither the name of the copyright holder, the names of its + contributors, nor any trademarks held by the copyright holder may be used + to endorse or promote products or services built using the Product without + specific prior written permission. + +6. Any modifications are clearly outlined in release documentation and are + specifically mentioned as not being a part of an official Product release. + No additional restrictions to this license may be made when distributing + modifications. + +7. For the avoidance of doubt, this license prohibits sublicensing of the + Product. + +8. Any breach of this license by licensee must be resolved within 30 days. + Failure to do so results in the termination of this license. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +To obtain a non-profit or commercial license for Product, please contact +Digital Bazaar, Inc. at the following email address: + +Digital Bazaar diff --git a/README.md b/README.md new file mode 100644 index 0000000..06e90df --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# bedrock-module-template-http \ No newline at end of file diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 0000000..f6120da --- /dev/null +++ b/lib/config.js @@ -0,0 +1,13 @@ +/*! + * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + */ +import bedrock from 'bedrock'; +const {config} = bedrock; + +const namespace = 'module-template-http'; +const cfg = config[namespace] = {}; + +const basePath = '/foo'; +cfg.routes = { + basePath +}; diff --git a/lib/http.js b/lib/http.js new file mode 100644 index 0000000..a57c31d --- /dev/null +++ b/lib/http.js @@ -0,0 +1,14 @@ +/*! + * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + */ +import {asyncHandler} from 'bedrock-express'; +import bedrock from 'bedrock'; +const {config} = bedrock; + +bedrock.events.on('bedrock-express.configure.routes', app => { + const {routes} = config['module-template-http']; + app.post( + routes.basePath, + asyncHandler(async (/*req, res*/) => { + })); +}); diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..e731f70 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,8 @@ +/*! + * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + */ +'use strict'; + +// translate `main.js` to CommonJS +require = require('esm')(module); +module.exports = require('./main.js'); diff --git a/lib/main.js b/lib/main.js new file mode 100644 index 0000000..7e65f16 --- /dev/null +++ b/lib/main.js @@ -0,0 +1,7 @@ +/*! + * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + */ +import 'bedrock-express'; + +import './config.js'; +import './http.js'; diff --git a/package.json b/package.json new file mode 100644 index 0000000..fb148e6 --- /dev/null +++ b/package.json @@ -0,0 +1,42 @@ +{ + "name": "bedrock-module-template-http", + "version": "0.0.1-0", + "description": "Bedrock HTTP API", + "main": "./lib", + "scripts": { + "lint": "eslint ." + }, + "repository": { + "type": "git", + "url": "https://github.com/digitalbazaar/bedrock-module-template-http" + }, + "keywords": [ + "bedrock" + ], + "author": { + "name": "Digital Bazaar, Inc.", + "email": "support@digitalbazaar.com", + "url": "https://digitalbazaar.com" + }, + "bugs": { + "url": "https://github.com/digitalbazaar/bedrock-module-template-http/issues" + }, + "homepage": "https://github.com/digitalbazaar/bedrock-module-template-http", + "dependencies": { + "esm": "^3.2.25" + }, + "peerDependencies": { + "bedrock": "^4.1.1", + "bedrock-express": "^3.2.0" + }, + "directories": { + "lib": "./lib" + }, + "devDependencies": { + "eslint": "^7.14.0", + "eslint-config-digitalbazaar": "^2.6.1" + }, + "engines": { + "node": ">=12" + } +} diff --git a/test/mocha/.eslintrc b/test/mocha/.eslintrc new file mode 100644 index 0000000..f9f5022 --- /dev/null +++ b/test/mocha/.eslintrc @@ -0,0 +1,9 @@ +{ + "env": { + "mocha": true + }, + "globals": { + "assertNoError": true, + "should": true + } +} diff --git a/test/mocha/10-api.js b/test/mocha/10-api.js new file mode 100644 index 0000000..6157d46 --- /dev/null +++ b/test/mocha/10-api.js @@ -0,0 +1,7 @@ +/* + * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + */ + +describe('api', () => { + it('should work'); +}); diff --git a/test/package.json b/test/package.json new file mode 100644 index 0000000..752b392 --- /dev/null +++ b/test/package.json @@ -0,0 +1,31 @@ +{ + "name": "bedrock-module-template-http-test", + "version": "0.0.1-0", + "private": true, + "scripts": { + "test": "node --preserve-symlinks test.js test", + "coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary npm test", + "coverage-ci": "cross-env NODE_ENV=test nyc --reporter=lcovonly npm test", + "coverage-report": "nyc report" + }, + "dependencies": { + "bedrock": "^4.1.1", + "bedrock-express": "^3.2.0", + "bedrock-https-agent": "^2.0.0", + "bedrock-module-template-http": "file:..", + "bedrock-mongodb": "^8.2.0", + "bedrock-server": "^2.7.0", + "bedrock-test": "^5.3.2", + "cross-env": "^7.0.3", + "nyc": "^15.1.0" + }, + "nyc": { + "excludeNodeModules": false, + "include": [ + "node_modules/bedrock-module-template-http/**" + ], + "exclude": [ + "node_modules/bedrock-module-template-http/node_modules/**" + ] + } +} diff --git a/test/test.config.js b/test/test.config.js new file mode 100644 index 0000000..2bd6421 --- /dev/null +++ b/test/test.config.js @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + */ +'use strict'; + +const {config} = require('bedrock'); +const path = require('path'); + +// MongoDB +config.mongodb.name = 'bedrock_module_template_http_test'; +config.mongodb.dropCollections.onInit = true; +config.mongodb.dropCollections.collections = []; + +config.mocha.tests.push(path.join(__dirname, 'mocha')); + +// allow self-signed certs in test framework +config['https-agent'].rejectUnauthorized = false; diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..cad3ac1 --- /dev/null +++ b/test/test.js @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2021 Digital Bazaar, Inc. All rights reserved. + */ +'use strict'; + +const bedrock = require('bedrock'); +require('bedrock-https-agent'); +require('bedrock-mongodb'); +require('bedrock-module-template-http'); + +require('bedrock-test'); +bedrock.start();