This package has been deprecated

Author message:

This project has been renamed to microfeedback-core. Install using microfeedback-core instead.

micro-wishes

0.5.0 • Public • Published

micro-wishes

Build Status

Core library for building Wishes microservices.

What is a Wishes microservice?

In short: an easily-deployable HTTP microservice for collecting user feedback about your apps.

Installation

Requires Node>=7.

npm install micro-wishes --save
# OR
yarn add micro-wishes

Usage

The micro-wishes function is the only public API. It takes a backend function which contains the code user feedback (e.g. post a GitHub issue, send an email). The second argument, attributes, is an Object that describes the backend (e.g. name, version, description).

The first argument to the backend function is the parsed client input which will contain--at a minimum--an entry named body with the feedback content. The backend function also receives the request (req) and response (res) objects. See the micro docs for more information about these objects.

The micro-wishes function returns a micro request handler.

// index.js
const { createError } = require('micro');
const wishes = require('micro-wishes');
const sendEmail = require('./email-library');
 
const EmailBackend = async ({ name, body }, req, res) => {
  const email = process.env.FEEDBACK_EMAIL;  // where to receive feedback
  const subject = `[wishes] Feedback from ${name}`;
  const content = `${name} posted feedback on your app:
 
${body}
 
Cheers,
The Wishes Robot`;
  try {
    const result = await sendEmail(email, { subject, content });
    return { status: result.status };
  } catch (err) {
    throw new createError(400, 'Could not send email', err);
  }
};
 
module.exports = wishes(EmailBackend, {
  name: 'email',
  version: '1.0.0',
});

The service can then be run with the micro CLI via npm start.

{
  "name": "micro-wishes-email",
  "dependencies": {
    "micro": "x.y.z",
    "micro-wishes": "x.y.z"
  },
  "main": "index.js",
  "scripts": {
    "start": "micro"
  }
}
npm start

Backends

Development

  • Fork and clone this repo. cd into the project directory.
  • yarn install
  • To run tests: npm test
  • To run the example server with auto-reloading: npm run dev

Debugging in tests with iron-node

Add debugger statements, then run the following:

yarn global add iron-node
npm run test:debug

License

MIT Licensed.

Package Sidebar

Install

npm i micro-wishes

Weekly Downloads

0

Version

0.5.0

License

MIT

Last publish

Collaborators

  • sloria