# jay-npm

> NPM module for Jay

Latest version **0.10.5** (published 2016-01-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install jay-npm
pnpm add jay-npm
yarn add jay-npm
bun add jay-npm
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.10.5 |
| Published | 2016-01-11 |
| First published | 2015-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 7 |
| Known vulnerabilities | 0 (+15 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Martin Sookael |
| Maintainers | martinsookael |

## Links

- npm: https://www.npmjs.com/package/jay-npm
- Repository: https://github.com/jayJs/jay-npm
- Issues: https://github.com/jayJs/jay-npm/issues
- npm.io page: https://npm.io/package/jay-npm

## Dependencies (7)

- [fb](https://npm.io/package/fb.md) ^0.7.0
- [jimp](https://npm.io/package/jimp.md) ^0.2.4
- [kaiseki](https://npm.io/package/kaiseki.md) ~0.5.6
- [image-size](https://npm.io/package/image-size.md) ^0.3.5
- [jwt-simple](https://npm.io/package/jwt-simple.md) ^0.2.0
- [multiparty](https://npm.io/package/multiparty.md) ~4.1.1
- [sanitize-html](https://npm.io/package/sanitize-html.md) ^1.11.1

## Recent versions

- 0.10.5 (latest) — 2016-01-11
- 0.10.4 — 2016-01-11
- 0.10.3 — 2016-01-11
- 0.10.2 — 2015-11-21
- 0.10.1 — 2015-11-21
- 0.7.5 — 2015-11-21
- 0.10.0 — 2015-08-28
- 0.7.4 — 2015-06-03
- 0.7.3 — 2015-06-03
- 0.7.2 — 2015-06-02
- 0.6.6 — 2015-05-13
- 0.6.4 — 2015-05-12
- 0.6.3 — 2015-05-11
- 0.6.1 — 2015-04-17
- 0.5.7 — 2015-03-29
- … 6 more at https://npm.io/package/jay-npm/versions

## README

JAY-NPM
===================

Server for Single Page App relying on [Jay](https://github.com/jayJs/jay).  
Use [Node-Jay](https://github.com/jayJs/node-jay) as sample of usage.  

**Instant back-end**  
Database via Kaiseki and Parse.com.
Authentication based on FB SDK and jwt-simle tokens.  

**INSTALLATION**  
(Assuming you have npm installed)  
```
npm install jay-npm  
```  
Set your settings at config.js. It also accepts process.env variables so you can run it like this:  
```
PARSEID='myParseId' PARSEKEY='MyParseRESTAPIKey' node app.js
```
In order for everything to work properly Facebook app and parse.com credentials are required.    
Set config.jwtSimple.secret into a string of your own choice.    
  
**USAGE**  
Jay front end component calls "/api/j" for GET and POST (JSONP) calls.  
Jay-npm helps to respond to these calls. This is an example of receiving and replying with an Express server.

```
var Jay = require('jay-npm');

app.get('/api/j', function(req, res){
  Jay.get(req, res, config, function(data){
    res.jsonp(data);
  });
});
```  
Please note that for this sample also express needs to be installed.  
Check out [Node-Jay](https://github.com/jayJs/node-jay/blob/master/app.js) for a complete example.  

**API**  
**FB SDK Authentication**  
Facebook SDK is added and used for authentication.  
Greetings for [AndrusAsumets](https://github.com/AndrusAsumets) for help with this.

**ensureAuthenticated**  
Compares users token with server token. If match is found the functions is fired, else error message is returned with response.  
```
app.post('/api/j', Jay.ensureAuthenticated, function(req, res){
  Jay.post(req, res, config, function(data){
    res.jsonp(data);
  })
});
```
**get**  
Retrieves data from Parse.com and returns as object.  
```
Jay.get(req, res, config, function(data){
  res.jsonp(data);
});
```
**post**  
Parses your formdata and saves it to Parse.com.
If files are added, they are separately uploaded to Parse and added to the object.  
Returns ObjectId.  
```
app.post('/api/j', Jay.ensureAuthenticated, function(req, res){
  Jay.post(req, res, config, function(data){
    res.jsonp(data);
  })
});
```
**put**  
Updates the post.  
Returns ObjectId.  
```
app.put('/api/j', function(req, res){
  Jay.put(req, res, config, function(data){
    res.jsonp(data);
  })
});
```

**delete**  
Deletes the post.  
Returns ObjectId.  
```
app.delete('/api/j', function(req, res){
  Jay.delete(req, res, config, function(data){
    res.jsonp(data);
  })
});
```

**query**  
Query for data.  
Front end comes with this: query(table, limit, key, value, order).  
```
app.get('/api/j/query', function(req, res){
  Jay.query(req, res, config, function(data){
    res.jsonp(data);
  });
});
```

**protectedCallback()**  
All callbacks to and from Jay are protected with a check to make sure the headers are not already sent.  

**thumbnails**
*alfa*
Thumbnails are currently created to your server, so Heroku might not be a good choice for this, because it's ephemeral file system (deletes everything that is not added to your git at least once every 24 h).
Add this to config to create thumbnails:
```
config.thumbnails = {}
config.thumbnails.enabled = false;
config.thumbnails.quality = 20;
```


**Licence**  

The MIT License (MIT)  

Copyright (c) 2015 Martin Sookael  

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---
_Source: https://npm.io/package/jay-npm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
