@adobe/aio-lib-events
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -13,9 +13,9 @@ <!-- | ||
[![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 | ||
@@ -25,3 +25,3 @@ ### Installing | ||
```bash | ||
$ npm install @{{REPO}} | ||
$ npm install @adobe/aio-lib-events | ||
``` | ||
@@ -33,7 +33,7 @@ | ||
```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>') | ||
} | ||
@@ -45,7 +45,7 @@ ``` | ||
```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>') | ||
@@ -64,6 +64,30 @@ // call methods | ||
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(() => 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 | ||
@@ -70,0 +94,0 @@ |
module.exports = { | ||
testEnvironment: 'node', | ||
setupFilesAfterEnv: [ | ||
'../test/jest/jest.setup.js' | ||
], | ||
testRegex: './e2e/e2e.js' | ||
} |
{ | ||
"name": "@adobe/aio-lib-events", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Adobe I/O Events", | ||
"repository": "https://github.com/adobe/aio-lib-events/", | ||
"repository": "https://github.com/adobe/aio-lib-events", | ||
"license": "Apache-2.0", | ||
@@ -18,3 +18,3 @@ "main": "src/index.js", | ||
"@adobe/aio-lib-core-errors": "^3.0.0", | ||
"@adobe/aio-lib-core-logging": "1.0.0", | ||
"@adobe/aio-lib-core-logging": "^1.1.2", | ||
"@adobe/aio-lib-core-networking": "^1.0.0", | ||
@@ -40,3 +40,3 @@ "cross-fetch": "^3.0.4", | ||
"eslint-plugin-standard": "^4.0.1", | ||
"eslint-plugin-jsdoc": "^25.2.0", | ||
"eslint-plugin-jsdoc": "^25.4.1", | ||
"jest": "^26.0.1", | ||
@@ -43,0 +43,0 @@ "jest-fetch-mock": "^3.0.3", |
<!-- | ||
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"); | ||
@@ -13,10 +13,12 @@ you may not use this file except in compliance with the License. You may obtain a copy | ||
[![Version](https://img.shields.io/npm/v/@.svg)](https://npmjs.org/package/@) | ||
[![Downloads/week](https://img.shields.io/npm/dw/@.svg)](https://npmjs.org/package/@) | ||
[![Build Status](https://travis-ci.com/.svg?branch=master)](https://travis-ci.com/) | ||
[![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/.svg)](https://greenkeeper.io/) | ||
[![Codecov Coverage](https://img.shields.io/codecov/c/github//master.svg?style=flat-square)](https://codecov.io/gh//) | ||
[![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) | ||
[![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 Events Lib | ||
Node Javascript API wrapping the [Adobe I/O Events API](https://www.adobe.io/apis/experienceplatform/events.html). | ||
### Installing | ||
@@ -51,3 +53,3 @@ | ||
try { | ||
// get profiles by custom filters | ||
// use one of the get methods | ||
const result = await client.getSomething({}) | ||
@@ -80,3 +82,3 @@ console.log(result) | ||
// To stop receiving events from this subscription based on a timeout | ||
setTimeout(() => this.subscription.unsubscribe(), <timeout in ms>) | ||
setTimeout(() => subscription.unsubscribe(), <timeout in ms>) | ||
} | ||
@@ -123,3 +125,4 @@ | ||
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 | ||
@@ -150,3 +153,3 @@ **Kind**: global class | ||
* [.publishEvent(cloudEvent)](#EventsCoreAPI+publishEvent) ⇒ <code>Promise.<string></code> | ||
* [.getEventsFromJournal(journalUrl, [eventsJournalOptions])](#EventsCoreAPI+getEventsFromJournal) ⇒ <code>Promise.<object></code> | ||
* [.getEventsFromJournal(journalUrl, [eventsJournalOptions], [fetchResponseHeaders])](#EventsCoreAPI+getEventsFromJournal) ⇒ <code>Promise.<object></code> | ||
* [.getEventsObservableFromJournal(journalUrl, [eventsJournalOptions], [eventsJournalPollingOptions])](#EventsCoreAPI+getEventsObservableFromJournal) ⇒ <code>Observable</code> | ||
@@ -415,3 +418,3 @@ * [.verifySignatureForEvent(event, clientSecret, signatureHeaderValue)](#EventsCoreAPI+verifySignatureForEvent) ⇒ <code>boolean</code> | ||
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. | ||
@@ -428,3 +431,3 @@ | ||
### eventsCoreAPI.getEventsFromJournal(journalUrl, [eventsJournalOptions]) ⇒ <code>Promise.<object></code> | ||
### eventsCoreAPI.getEventsFromJournal(journalUrl, [eventsJournalOptions], [fetchResponseHeaders]) ⇒ <code>Promise.<object></code> | ||
Get events from a journal. | ||
@@ -439,2 +442,3 @@ | ||
| [eventsJournalOptions] | [<code>EventsJournalOptions</code>](#EventsJournalOptions) | Query options to send with the URL | | ||
| [fetchResponseHeaders] | <code>boolean</code> | Set this to true if you want to fetch the complete response headers | | ||
@@ -441,0 +445,0 @@ <a name="EventsCoreAPI+getEventsObservableFromJournal"></a> |
@@ -17,2 +17,4 @@ /* | ||
/* global Observable */ // for linter | ||
const { reduceError, appendQueryParams, parseLinkHeader, parseRetryAfterHeader } = require('./helpers') | ||
@@ -63,3 +65,4 @@ const loggerNamespace = '@adobe/aio-lib-events' | ||
* 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 | ||
*/ | ||
@@ -375,4 +378,8 @@ 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 | ||
@@ -421,5 +428,6 @@ * @returns {Promise<string>} Returns OK/ undefined in case of success and error in case of failure | ||
* @param {EventsJournalOptions} [eventsJournalOptions] Query options to send with the URL | ||
* @param {boolean} [fetchResponseHeaders] Set this to true if you want to fetch the complete response headers | ||
* @returns {Promise<object>} with the response json includes events and links (if available) | ||
*/ | ||
async getEventsFromJournal (journalUrl, eventsJournalOptions) { | ||
async getEventsFromJournal (journalUrl, eventsJournalOptions, fetchResponseHeaders) { | ||
const url = appendQueryParams(journalUrl, eventsJournalOptions) | ||
@@ -442,2 +450,5 @@ const headers = {} | ||
} | ||
if (fetchResponseHeaders) { | ||
result.responseHeaders = response.headers.raw() | ||
} | ||
return new Promise((resolve, reject) => { | ||
@@ -463,4 +474,7 @@ resolve(result) | ||
/** | ||
* 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) | ||
@@ -494,2 +508,3 @@ * @param {EventsJournalOptions} [eventsJournalOptions] Query options to send with the Journal URL | ||
* @returns {Function} retryOnFunction {function(...[*]=)} | ||
* @private | ||
*/ | ||
@@ -564,3 +579,2 @@ __getRetryOn (retries) { | ||
* @param {object} sdkDetails SDK details to be logged in case of error | ||
* @returns {undefined|*} SDK details with sensitive information masked | ||
* @private | ||
@@ -576,3 +590,3 @@ */ | ||
* | ||
* @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 | ||
@@ -579,0 +593,0 @@ * @private |
@@ -17,2 +17,4 @@ /* | ||
/* global EventsCoreAPI, EventsJournalOptions, EventsJournalPollingOptions, Observer, Subscription */ // for linter | ||
class EventsConsumerFromJournal extends Rx.Subject { | ||
@@ -55,3 +57,3 @@ /** | ||
* | ||
* @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 | ||
@@ -58,0 +60,0 @@ */ |
@@ -10,3 +10,8 @@ { | ||
"node/no-unpublished-require": 0 | ||
}, | ||
"settings": { | ||
"jsdoc": { | ||
"ignorePrivate": true | ||
} | ||
} | ||
} |
@@ -12,2 +12,4 @@ /* | ||
/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "checkErrorResponse"] }] */ | ||
const sdk = require('../src') | ||
@@ -477,2 +479,3 @@ const mock = require('./mock') | ||
expect(res1.events[0].position).toBe('position-2') | ||
expect(res1.responseHeaders).toBeUndefined() | ||
}) | ||
@@ -530,2 +533,10 @@ it('204 response on fetch from journal with retry after as number', async () => { | ||
}) | ||
it('200 response on fetch from journal with response headers', async () => { | ||
const sdkClient = await createSdkClient() | ||
mockExponentialBackoff(mock.data.journalResponseBody, mock.data.journalResponseHeader200) | ||
const res = await sdkClient.getEventsFromJournal(journalUrl, {}, true) | ||
expect(res.link.next).toBe('http://journal-url/events-fast/organizations/orgId/integrations/integId/regId?since=position-1') | ||
expect(res.events[0].position).toBe('position-2') | ||
expect(res.responseHeaders).toBeDefined() | ||
}) | ||
}) | ||
@@ -532,0 +543,0 @@ |
@@ -224,4 +224,3 @@ /* | ||
* Mock implementation of get events from journal that returns a mock value | ||
* | ||
* @param mockResponse | ||
* @private | ||
*/ | ||
@@ -238,2 +237,3 @@ function getMockImplementation (mockResponse) { | ||
* Mock implementation of a function that returns an error | ||
* @private | ||
*/ | ||
@@ -240,0 +240,0 @@ function getMockErrorResponse () { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
170607
35
2734
531
2
+ Added@adobe/aio-lib-core-logging@1.2.0(transitive)
- Removed@adobe/aio-lib-core-logging@1.0.0(transitive)