@fireflyxd/fm-backend v1.0.6
fm-backend
An npm module to house commonly used backend functions
⚠️ Do not put private keys or anything else sensitive in this repo — it is public on npm. ️️️⚠️
Development
fm-backend
, written in Typescript, is meant to serve as an npm package for commonly used backend functions.
It is meant to be used within Firefly, not by clients or anyone outside of Firefly.
If you're copying and pasting the same functionality across multiple repos, that functionality should probably go here.
To build the project locally, run:
npm run build
A linter and formatter are included. To lint the project, run:
npm run lint
To format the project using prettier, run:
npm run prettier
Deployment
CircleCI manages deployments to npm via the config in /.circleci/config.yml
.
The published npm module is called @fireflyxd/fm-backend
. It may be found at npm here.
In order to publish to npm, update the version number in package.json, create a tag and push it to the Github repo. Creating and pushing a tag looks something like this:
git tag v0.0.8
git push origin v0.0.8
CircleCI is configured to only run when pushing a tag.
Usage
To use fm-backend
in a backend project, it must first be installed:
npm install --save @fireflyxd/fm-backend
Then, import the package to use it in a file:
import * as FmBackend from '@fireflyxd/fm-backend';
User
The User
class has several functions that return promises for data commonly associated with users.
The User
class is instantiated with a params
object. Both master_id
and enagement_id
are required.
import * as FmBackend from '@fireflyxd/fm-backend';
const user = new FmBackend.User({
master_id: '123456-3367-4d50-1234-e180b4d6d0b6',
engagement_id: '123456-b78c-4d8e-1234-132615d8d8c3'
});
It's also possible to import classes and types indidually:
import { User } from '@fireflyxd/fm-backend';
const user = new User({
master_id: '123456-3367-4d50-1234-e180b4d6d0b6',
engagement_id: '123456-b78c-4d8e-1234-132615d8d8c3'
});
Then, the user's engagement, registration, REMS config and/or program config may be retrieved:
import { User, IEngagement } from '@fireflyxd/fm-backend';
someFunction = async () => {
const user = new User({
master_id: '123456-3367-4d50-1234-e180b4d6d0b6',
engagement_id: '123456-b78c-4d8e-1234-132615d8d8c3'
});
/**
* Optionally use the imported IEngagement type to set the type of the
* engagement variable
*/
let engagement: IEngagement;
/**
* Get the user's engagement with getEngagement()
*/
engagement = await user.getEngagement();
// engagement may be null, so be sure to check:
if (!engagement) {
return null;
}
/**
* Get the user's registration with getRegistration()
*/
const registration = await user.getRegistration();
// registration may be null, so be sure to check:
if (!registration) {
return null;
}
/**
* Get the program configuration that the user went through
* with getProgramConfig()
*/
const programConfig = await user.getProgramConfig();
// programConfig may be null, so be sure to check:
if (!programConfig) {
return null;
}
/**
* Get the REMS config that the user went through with
* getRemsConfig()
*
* remsConfig will be null if REMS is not required for the
* client. If REMS is required, getRemsConfig() will return a
* value, and remsConfig.rems_required will be true.
*
* REMS is rare. Most clients will not require REMS.
*/
const remsConfig = await user.getRemsConfig();
// remsConfig may be null, so be sure to check:
if (!remsConfig) {
return null;
}
}
Types
Types may be imported individualy in projects. They are documented in interfaces throughout the package.
For example, to see types associated with User, see /src/User/index.ts.