# @agm-as/bridge

provides easy access to `agm-services` and their data.

```
npm install @agm-as/bridge
```

## Publishing

Update the `version` in `package.json` [according to the best practices of semantic versioning](https://semver.org), and commit (the version change) as `:bookmark: Update bridge version`, then run `npm publish` to realise the changes.

## Notes

* `organization` is a filtering object that takes either `firebaseId`, `titleId`, `environmentId`, `hostname`, or `titleCode`.
* `user` is a filtering object that takes either `emailAddress`, `customerId`, or `customerNumber`.
* `lilypadsOptions` is an object sent to [the `lilypads` npm module](https://www.npmjs.com/package/lilypads#options--object--required).

## Methods

### `orgs`

```javascript
import * as orgs from '@agm-as/bridge/orgs';

orgs.getOrganizations({hostname: 'varden.no'})
	.then(console.log);
```

#### `getOrganizations` _`(organization, lilypadsOptions)`_

```javascript
import getOrganizations from '@agm-as/bridge/orgs';

getOrganizations().then((organizations) => console.log(organizations));
```

### `users`

```javascript
import * as users from '@agm-as/bridge/users';

users.getUserConstellation({emailAddress: 'demo-n@agderposten.no'})
	.then(console.log);
```

#### `authenticateUser` _`(username, password, organization)`_

```javascript
import authenticateUser from '@agm-as/bridge/users/authenticate';
// or import {authenticateUser} from '@agm-as/bridge/users';

authenticateUser('demo-n@agderposten.no', 'DemoUser5678', {titleId: 1})
	.then((result) => console.log(result));
```

#### `logoutUser` _`(token)`_

```javascript
import logoutUser from '@agm-as/bridge/users/logout';
// or import {logoutUser} from '@agm-as/bridge/users';

logoutUser(token)
	.then(() => console.log('logged out'));
```

#### `validateUserAccess` _`(token, organization, requestOptions)`_

* `requestOptions`
	* `requestOptions.url` _`(string)`_: resource url
	* `requestOptions.cxenseUserId` _`(string)`_: cxense user id
	* `requestOptions.ipAddress` _`(string)`_: client ip address
	* `requestOptions.referrer` _`(string)`_: client referrer

```javascript
import validateUserAccess from '@agm-as/bridge/users/validate-access';
// or import {validateUserAccess} from '@agm-as/bridge/users';

validateUserAccess(token, {titleId: 1}, {url: 'https://agderposten.no'})
	.then((result) => console.log(result));
```

#### `getUserConstellation` _`(user, organization, requestOptions, lilypadsOptions)`_

* `requestOptions`
	* `requestOptions.token` _`(string)`_: user authentication token

```javascript
import getUserConstellation from '@agm-as/bridge/users/constellation';
// or import {getUserConstellation} from '@agm-as/bridge/users';

getUserConstellation({customerId: '920538'})
	.then((constellation) => console.log(constellation));
```

### `news`

```javascript
import * as news from '@agm-as/bridge/news';

news.getNews({url: 'https://www.agderposten.no/trafikk/oppdaget-feil-pa-23-km-midtdeler-pa-e18'})
	.then(console.log);
```

#### `getNews` _`(news, lilypadsOptions)`_

```javascript
import getNews from '@agm-as/bridge/news';

getNews({url: 'https://www.agderposten.no/trafikk/oppdaget-feil-pa-23-km-midtdeler-pa-e18'})
	.then((news) => console.log(news));
```
