Skip to content

Commit

Permalink
fix: badges and docs (#4)
Browse files Browse the repository at this point in the history
* fix: docs in code and template

* fix: linting in tests
  • Loading branch information
shazron committed May 12, 2020
1 parent 811f1d1 commit 529c02e
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 24 deletions.
9 changes: 5 additions & 4 deletions README.md
@@ -1,5 +1,5 @@
<!--
Copyright 2019 Adobe. All rights reserved.
Copyright 2020 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Expand All @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
-->

[![Version](https://img.shields.io/npm/v/@adobe/aio-lib-events.svg)](https://www.npmjs.org/package/@adobe/aio-lib-events)
[![Version](https://img.shields.io/npm/v/@adobe/aio-lib-events.svg)](https://npmjs.org/package/@adobe/aio-lib-events)
[![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-lib-events.svg)](https://npmjs.org/package/@adobe/aio-lib-events)
[![Build Status](https://travis-ci.com/adobe/aio-lib-events.svg?branch=master)](https://travis-ci.com/adobe/aio-lib-events)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Greenkeeper badge](https://badges.greenkeeper.io/adobe/aio-lib-events.svg)](https://greenkeeper.io/)
Expand Down Expand Up @@ -117,7 +117,8 @@ and max number of retries</p>
## EventsCoreAPI
This class provides methods to call your Adobe I/O Events APIs.
Before calling any method initialize the instance by calling the `init` method on it
with valid values for organizationId, apiKey and accessToken
with valid values for organizationId, apiKey, accessToken and optional http options such as timeout
and max number of retries

**Kind**: global class

Expand Down Expand Up @@ -407,7 +408,7 @@ Delete webhook registration
Publish Cloud Events

Event publishers can publish events to the Adobe I/O Events using this SDK. The events should follow Cloud Events 1.0 specification: https://github.com/cloudevents/spec/blob/v1.0/spec.md.
As of now, only application/json is accepted as the content-type for the "data" field of the cloud event.
As of now, only application/json is accepted as the content-type for the "data" field of the cloud event.
If retries are set, publish events are retried on network issues, 5xx and 429 error response codes.

**Kind**: instance method of [<code>EventsCoreAPI</code>](#EventsCoreAPI)
Expand Down
48 changes: 36 additions & 12 deletions docs/readme_template.md
Expand Up @@ -10,40 +10,40 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
-->

[![Version](https://img.shields.io/npm/v/@{{REPO}}.svg)](https://npmjs.org/package/@{{REPO}})
[![Downloads/week](https://img.shields.io/npm/dw/@{{REPO}}.svg)](https://npmjs.org/package/@{{REPO}})
[![Build Status](https://travis-ci.com/{{REPO}}.svg?branch=master)](https://travis-ci.com/{{REPO}})
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Greenkeeper badge](https://badges.greenkeeper.io/{{REPO}}.svg)](https://greenkeeper.io/)
[![Codecov Coverage](https://img.shields.io/codecov/c/github/{{REPO}}/master.svg?style=flat-square)](https://codecov.io/gh/{{REPO}}/)
[![Version](https://img.shields.io/npm/v/@adobe/aio-lib-events.svg)](https://npmjs.org/package/@adobe/aio-lib-events)
[![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-lib-events.svg)](https://npmjs.org/package/@adobe/aio-lib-events)
[![Build Status](https://travis-ci.com/adobe/aio-lib-events.svg?branch=master)](https://travis-ci.com/adobe/aio-lib-events)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Greenkeeper badge](https://badges.greenkeeper.io/adobe/aio-lib-events.svg)](https://greenkeeper.io/)
[![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-lib-events/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-lib-events/)

# Adobe I/O Lib
# Adobe I/O Events Lib

### Installing

```bash
$ npm install @{{REPO}}
$ npm install @adobe/aio-lib-events
```

### Usage
1) Initialize the SDK

```javascript
const sdk = require('@{{REPO}}')
const sdk = require('@adobe/aio-lib-events')

async function sdkTest() {
//initialize sdk
const client = await sdk.init('<tenant>', 'x-api-key', '<valid auth token>')
const client = await sdk.init('<organization id>', 'x-api-key', '<valid auth token>', '<options>')
}
```

2) Call methods using the initialized SDK

```javascript
const sdk = require('@{{REPO}}')
const sdk = require('@adobe/aio-lib-events')

async function sdkTest() {
// initialize sdk
const client = await sdk.init('<tenant>', 'x-api-key', '<valid auth token>')
const client = await sdk.init('<organization id>', 'x-api-key', '<valid auth token>', '<options>')

// call methods
try {
Expand All @@ -57,10 +57,34 @@ async function sdkTest() {
}
```

3) Using the poller for journalling

```javascript
const sdk = require('@adobe/aio-lib-events')

async function sdkTest() {
// initialize sdk
const client = await sdk.init('<organization id>', 'x-api-key', '<valid auth token>', '<http options>')
// get the journalling observable
const journalling = client.getEventsObservableFromJournal('<journal url>', '<journalling options>')
// call methods
const subscription = journalling.subscribe({
next: (v) => console.log(v), // Action to be taken on event
error: (e) => console.log(e), // Action to be taken on error
complete: () => console.log('Complete') // Action to be taken on complete
})

// To stop receiving events from this subscription based on a timeout
setTimeout(() => this.subscription.unsubscribe(), <timeout in ms>)
}

```
One observable can have multiple subscribers. Each subscription can be handled differently.
For more details on using the poller for Journalling check <a href="#EventsCoreAPI+getEventsObservableFromJournal">getEventsObservableFromJournal</a>

{{>main-index~}}
{{>all-docs~}}


### Debug Logs

```bash
Expand Down
20 changes: 15 additions & 5 deletions src/index.js
Expand Up @@ -14,6 +14,8 @@ governing permissions and limitations under the License.

'use strict'

/* global Observable */ // for linter

const { reduceError, appendQueryParams, parseLinkHeader, parseRetryAfterHeader } = require('./helpers')
const loggerNamespace = '@adobe/aio-lib-events'
const logger = require('@adobe/aio-lib-core-logging')(loggerNamespace,
Expand Down Expand Up @@ -59,7 +61,8 @@ function init (organizationId, apiKey, accessToken, httpOptions) {
/**
* This class provides methods to call your Adobe I/O Events APIs.
* Before calling any method initialize the instance by calling the `init` method on it
* with valid values for organizationId, apiKey and accessToken
* with valid values for organizationId, apiKey, accessToken and optional http options such as timeout
* and max number of retries
*/
class EventsCoreAPI {
/**
Expand Down Expand Up @@ -370,7 +373,11 @@ class EventsCoreAPI {
*/

/**
* Publish cloud events to Adobe I/O Events
* Publish Cloud Events
*
* Event publishers can publish events to the Adobe I/O Events using this SDK. The events should follow Cloud Events 1.0 specification: https://github.com/cloudevents/spec/blob/v1.0/spec.md.
* As of now, only application/json is accepted as the content-type for the "data" field of the cloud event.
* If retries are set, publish events are retried on network issues, 5xx and 429 error response codes.
*
* @param {object} cloudEvent Object to be published to event receiver in cloud event format
* @returns {Promise<string>} Returns OK/ undefined in case of success and error in case of failure
Expand Down Expand Up @@ -455,7 +462,10 @@ class EventsCoreAPI {
* @property {number} [interval] Interval at which to poll the journal; If not provided, a default value will be used (optional)
*/
/**
* Get observable to start listening to journal events.
* getEventsObservableFromJournal returns an RxJS <a href="https://rxjs-dev.firebaseapp.com/guide/observable">Observable</a>
*
* One can go through the extensive documentation on <a href="https://rxjs-dev.firebaseapp.com/guide/overview">RxJS</a> in order to learn more
* and leverage the various <a href="https://rxjs-dev.firebaseapp.com/guide/operators">RxJS Operators</a> to act on emitted events.
*
* @param {string} journalUrl URL of the journal or 'next' link to read from (required)
* @param {EventsJournalOptions} [eventsJournalOptions] Query options to send with the Journal URL
Expand Down Expand Up @@ -485,6 +495,7 @@ class EventsCoreAPI {
*
* @param {number} retries Max number of retries
* @returns {Function} retryOnFunction {function(...[*]=)}
* @private
*/
__getRetryOn (retries) {
return function (attempt, error, response) {
Expand Down Expand Up @@ -554,7 +565,6 @@ class EventsCoreAPI {
* Hides sensitive information
*
* @param {object} sdkDetails SDK details to be logged in case of error
* @returns {undefined|*} SDK details with sensitive information masked
* @private
*/
__maskAuthData (sdkDetails) {
Expand All @@ -565,7 +575,7 @@ class EventsCoreAPI {
/**
* Set headers for every request
*
* @param headers Empty headers or headers with prefilled custom values
* @param {object} headers Empty headers or headers with prefilled custom values
* @returns {object} Headers common for all requests
* @private
*/
Expand Down
4 changes: 3 additions & 1 deletion src/journalling.js
Expand Up @@ -14,6 +14,8 @@ const { appendQueryParams } = require('./helpers')
const DEFAULT_INTERVAL = 2000
const Rx = require('rxjs')

/* global EventsCoreAPI, EventsJournalOptions, EventsJournalPollingOptions, Observer, Subscription */ // for linter

class EventsConsumerFromJournal extends Rx.Subject {
/**
* Construct and start an Adobe I/O event emitter.
Expand Down Expand Up @@ -51,7 +53,7 @@ class EventsConsumerFromJournal extends Rx.Subject {
* Overrides the subscribe of the Observable.
* On subscribing to the observable, we to subscribe to the subject
*
* @param observer Observer to the events arising from polling the journal
* @param {Observer} observer to the events arising from polling the journal
* @returns {Subscription} Returns a subscription to the subject
*/
subscribe (observer) {
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc.json
Expand Up @@ -7,5 +7,10 @@
},
"rules": {
"node/no-unpublished-require": 0
},
"settings": {
"jsdoc": {
"ignorePrivate": true
}
}
}
2 changes: 2 additions & 0 deletions test/index.test.js
Expand Up @@ -9,6 +9,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "checkErrorResponse"] }] */

const sdk = require('../src')
const mock = require('./mock')
const errorSDK = require('../src/SDKErrors')
Expand Down
4 changes: 2 additions & 2 deletions test/journalling.test.js
Expand Up @@ -221,8 +221,7 @@ describe('No subscribers to journalling', () => {

/**
* Mock implementation of get events from journal that returns a mock value
*
* @param mockResponse
* @private
*/
function getMockImplementation (mockResponse) {
return jest.fn().mockImplementation(function (journalUrl, options) {
Expand All @@ -234,6 +233,7 @@ function getMockImplementation (mockResponse) {

/**
* Mock implementation of a function that returns an error
* @private
*/
function getMockErrorResponse () {
return jest.fn().mockImplementation(function () {
Expand Down

0 comments on commit 529c02e

Please sign in to comment.