New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@indec/sivy

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@indec/sivy

The survey synchronization server for MongoDB

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-14.29%
Maintainers
2
Weekly downloads
 
Created
Source

Sivy · NPM version Build Status GitHub license

The survey synchronization server for MongoDB.

How to use

Setup

Install it:

npm install @indec/sivy

Sivy requires node@10.12

And add a script to your package.json like this:

{
  "scripts": {
    "start": "sivy",
    "dev": "sivy dev"
  }
}

The sivy dev command enables the hot code reloading. No server restart is needed.

Handlers

The file-system is the main API. Every .js file becomes a handler that gets automatically processed on every sync, and the container folder is when that handler is executed. The handlers support promise.

FolderInput parameters
dumpSurveys(surveyDump: SurveyDump, surveys: Array<object>)
receiveSurveys(surveys: Array<object>, syncLog: SyncLog)
preSaveSurvey(surveyAddress: SurveyAddress, survey: object, syncLog: SyncLog)
getSurveys(surveyAddresses: Array<SurveyAddress>, syncLog: SyncLog)
preSaveSyncLog(syncLog: SyncLog)

To log how many surveys we receive on a POST we can create a file into: receiveSurveys/helloWorld.js as the following:

module.exports = surveys => console.log(`Received surveys: ${surveys.length}`);

Model

By default the SurveyAddress has the following Mongoose's schema:

{
    dwellings: [{type: Mixed}],
    user: {type: ObjectId, required: true},
    address: {type: ObjectId, ref: 'Address', required: true},
    surveyAddressState: {type: Number},
    state: {type: Number},
    valid: {type: Number}
}

You can strongly type the Dwelling's schema defining a model/dwelling.js as the following:

module.exports = {
    order: {type: Number},
    dwellingCharacteristics: {
        ...
    }
};

Also, you can add additional attributes to the SurveyAddress's schema defining a model/surveyAddress.js as the following:

module.exports = {
    visits: [{
        order: {type: Number, required: true},
        date: {type: Date, required: true},
        comments: {type:String}
    }]
};

Environment variables

RequiredVariableDescriptionDefaults to
NODE_ENVDefines the running environmentdevelopment
PORTPort where sivy will listen3000
MONGODB_URIConnection string to the MongoDB servermongodb://localhost:27017
RECEIVE_ONLYTrue if Sivy works on receive_only modefalse
:bangbang:AUTH_CLIENT_SECRETThe secret to validate the JWT.
SURVEYS_COLLECTIONThe surveys collection name on MongoDBsurveyAddresses
SURVEYS_HISTORYKeeps a history of survey changestrue
SURVEYS_DUMPDumps every request to a collectionfalse
MORGAN_FORMATLog format used by Morgan packagedev on NODE_ENV=development, combined on NODE_ENV=production
DEBUGSet to sivy to turn on debug logging.

Authentication

Sivy expects an Authorization header on the HTTP request as the following:

Authorization: Bearer <jwt>

The JWT will be verified using the AUTH_CLIENT_SECRET defined in the environment variables and the verify method in the jsonwebtoken package.

Debug

To turn on the Sivy debug mode just set the environment variable DEBUG=sivy.

Production deployment

To deploy just run the sivy command:

sivy

For example, to deploy with now a package.json like follows is recommended:

{
  "name": "my-sync",
  "dependencies": {
    "@indec/sivy": "latest"
  },
  "scripts": {
    "start": "sivy"
  }
}

Note: It’s your responsibility to set NODE_ENV=production manually!

FAQs

Package last updated on 13 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc