# @noonlight/noonlight-sdk

> A Node.js wrapper around the Noonlight API

Latest version **0.1.2** (published 2018-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @noonlight/noonlight-sdk
pnpm add @noonlight/noonlight-sdk
yarn add @noonlight/noonlight-sdk
bun add @noonlight/noonlight-sdk
```

## 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.1.2 |
| Published | 2018-08-19 |
| First published | 2018-08-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Sean Mishra |
| Maintainers | cod3rguy |

## Links

- npm: https://www.npmjs.com/package/@noonlight/noonlight-sdk
- Repository: https://github.com/cod3rguy/noonlight-sdk-node
- Homepage: https://github.com/cod3rguy/noonlight-sdk-node#readme
- Issues: https://github.com/cod3rguy/noonlight-sdk-node/issues
- npm.io page: https://npm.io/package/@noonlight/noonlight-sdk

## Dependencies (4)

- [request](https://npm.io/package/request.md) ^2.88.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^2.2.0
- [request-promise](https://npm.io/package/request-promise.md) ^4.2.2

## Recent versions

- 0.1.2 (latest) — 2018-08-19
- 0.1.1 — 2018-08-19
- 0.1.0 — 2018-08-19

## README

# Noonlight SDK - Node.js Client Library
A Node.js wrapper around the Noonlight API. This library is part of the Noonlight SDK.

## Installation

```
npm i @noonlight/noonlight-sdk
```

## Usage

```
let access_token = 'eyJ0...' // acquire an access_token from Noonlight OAuth

const Noonlight = require('@noonlight/noonlight-sdk') // require the module
const nl = new Noonlight(access_token) // initialize

// Call methods
nl.createAlarm(nl.services(), '911 Washington Ave, St. Louis, MO, 63101')
```

## Reference

**constructor(token: *string*, uri?: *string*)**  
You can initialize the library by instantiating the base class using the `new` keyword. The `token` parameter is the *access_token* required to make requests to the Noonlight API and is hence a required parameter. The base URL for the API will be derived from the token if available. In case of error, make sure that you provided a valid token or explicitly provide the API base URL as the second parameter.

*Example Usage:*  
```
// Implicit URI detection
const nl = new noonlight('eyJ0...')

//Explicit URI declaration
const nl = new noonlight('eyJ0...', 'http://localhost:3000')
```

**services(code?: *string*)**  
Generates a `Services` object based on a given code, in the required JSON format to be used in other methods. The services are Police, Fire and Medical. The `code` parameter could be any combination of their initials in any order. It is also case insensitive. By default, the service object returned has `police` set to `true`.

*Example Usage:*  
```
console.log(nl.services())
// Output: { police: true, fire: false, medical: false }

console.log(nl.services('PF'))
// Output: { police: true, fire: true, medical: false }

nl.services('mf')
// Output: { police: false, fire: true, medical: true }

nl.services('FpM')
// Output: { police: true, fire: true, medical: true }
```

**createAlarm(services: *Services{}*, ...location: *...number|string*)**  
Creates a Noonlight alarm based on the given `location` and `services`. The `Services` object required by the `services` parameter can be generated using the `services()` method. For the `location`, you can either pass in an address string in the format:  
*line1, line2 (optional), city, state (2-digit state code), zip*  
or,   
the coordinates as three separate numbers - `latitude`, `longitude` and `accuracy` in that order. Improper or invalid parameters will result in an error.
The method returns a Promise which gets resolved into the response from the Noonlight API in event of successful alarm creation. The Promise will be rejected with an `Error` object in event of an error.

*Example Usage:*  
```
// Alarm creation with address
nl.createAlarm(nl.services(), '911 Washington Ave, St. Louis, MO, 63101')
  .then(result =>  console.log(result))
  .catch(err => console.log(err.message))

// Alarm creation with coordinates
nl.createAlarm(nl.services(), 34.32334, -117.3343, 5)
  .then(result =>  console.log(result))
  .catch(err => console.log(err.message))
```

## Contributions
Currently, public contributions to this project are not being accepted.

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