lib!: refactor HTTP bindings and specifications (#165)

This is a breaking change.

This commit makes a number of changes to the HTTP bindings code in an attempt
to simplify its usage and implementation. From a very high level, this inverts
the existing dependencies.

As an example, consider `lib/bindings/http/receiver_structured_1.js`.
https://github.com/cloudevents/sdk-javascript/blob/v1.0.0/lib/bindings/http/receiver_structured_0_3.js

This class instantiates `lib/bindings/http/receiver_structured.js` and delegates
its function invokations to it. This had the effect of requiring a user to know what
event versions they would be receiving. And for me personally was a little confusing
as a maintainer.

The change introduced here reverses that logic, so that the version agnostic receiver
is what the user instantiates. It instantiates the approrpiate version of a specific
receiever and delegates to it - reversing the dependencies.

I've also moved all of the top level directories related to HTTP versions into
`lib/bindings/http/v1` and `lib/bindings/http/v03` and generally done some rearranging
to make the repository structure cleaner and more organized.

Signed-off-by: Lance Ball <lball@redhat.com>
This commit is contained in:
Lance Ball 2020-05-18 11:34:22 -04:00 committed by GitHub
parent b99e6ea228
commit 6f0b5ea5f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 4591 additions and 898 deletions

535
docs/BinaryHTTPEmitter.html Normal file
View File

@ -0,0 +1,535 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
BinaryHTTPEmitter - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
BinaryHTTPEmitter
</h1>
<section>
<header>
<h2>
BinaryHTTPEmitter
</h2>
<div class="class-description">
<p>A class to emit binary CloudEvents over HTTP.</p>
</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<span class='name-container'>
<a class="link-icon" href="#BinaryHTTPEmitter">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="BinaryHTTPEmitter">
<span class="type-signature"></span>new BinaryHTTPEmitter<span class="signature">(version)</span><span class="type-signature"></span>
</h4>
</span>
<div class="description">
<p>Create a new {BinaryHTTPEmitter} for the provided CloudEvent specification version.
Once an instance is created for a given spec version, it may only be used to send
events for that version.
Default version is 1.0</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>version</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="description last">
<p>the CloudEvent HTTP specification version.
Default: 1.0</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_emitter_binary.js.html">bindings/http/emitter_binary.js</a>, <a href="bindings_http_emitter_binary.js.html#line35">line 35</a>
</li>
</ul>
</dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<span class='name-container'>
<a class="link-icon" href="#emit">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="emit">
<span class="type-signature">(async) </span>emit<span class="signature">(options, cloudevent)</span><span class="type-signature"> &rarr; {Promise}</span>
</h4>
</span>
<div class="description">
<p>Sends this cloud event to a receiver over HTTP.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>The configuration options for this event. Options
provided other than <code>url</code> will be passed along to Node.js <code>http.request</code>.
https://nodejs.org/api/http.html#http_http_request_options_callback</p>
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>url</code></td>
<td class="type">
<span class="param-type">
URL
</span>
</td>
<td class="description last">
<p>The HTTP/S url that should receive this event</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="name"><code>cloudevent</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>the CloudEvent to be sent</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_emitter_binary.js.html">bindings/http/emitter_binary.js</a>, <a href="bindings_http_emitter_binary.js.html#line55">line 55</a>
</li>
</ul>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -0,0 +1,715 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
BinaryHTTPReceiver - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
BinaryHTTPReceiver
</h1>
<section>
<header>
<h2>
BinaryHTTPReceiver
</h2>
<div class="class-description">
<p>A class that receives binary CloudEvents over HTTP. This class can be used
if you know that all incoming events will be using binary transport. If
events can come as either binary or structured, use {HTTPReceiver}.</p>
</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<span class='name-container'>
<a class="link-icon" href="#BinaryHTTPReceiver">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="BinaryHTTPReceiver">
<span class="type-signature"></span>new BinaryHTTPReceiver<span class="signature">(version)</span><span class="type-signature"></span>
</h4>
</span>
<div class="description">
<p>Creates a new BinaryHTTPReceiver to accept events over HTTP.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>version</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="description last">
<p>the Cloud Event specification version to use. Default &quot;1.0&quot;</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_receiver_binary.js.html">bindings/http/receiver_binary.js</a>, <a href="bindings_http_receiver_binary.js.html#line18">line 18</a>
</li>
</ul>
</dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<span class='name-container'>
<a class="link-icon" href="#check">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="check">
<span class="type-signature"></span>check<span class="signature">(payload, headers)</span><span class="type-signature"> &rarr; {void}</span>
</h4>
</span>
<div class="description">
<p>Checks an incoming HTTP request to determine if it conforms to the
Cloud Event specification for this receiver.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>payload</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>the HTTP request body</p>
</td>
</tr>
<tr>
<td class="name"><code>headers</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>the HTTP request headers</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_receiver_binary.js.html">bindings/http/receiver_binary.js</a>, <a href="bindings_http_receiver_binary.js.html#line36">line 36</a>
</li>
</ul>
</dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>if the event does not conform to the spec</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>Type</dt>
<dd>
<span class="param-type">
<a href="ValidationError.html">ValidationError</a>
</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#parse">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="parse">
<span class="type-signature"></span>parse<span class="signature">(payload, headers)</span><span class="type-signature"> &rarr; {<a href="CloudEvent.html">CloudEvent</a>}</span>
</h4>
</span>
<div class="description">
<p>Parses an incoming HTTP request, converting it to a {CloudEvent}
instance if it conforms to the Cloud Event specification for this receiver.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>payload</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>the HTTP request body</p>
</td>
</tr>
<tr>
<td class="name"><code>headers</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>the HTTP request headers</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_receiver_binary.js.html">bindings/http/receiver_binary.js</a>, <a href="bindings_http_receiver_binary.js.html#line49">line 49</a>
</li>
</ul>
</dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>of the event does not conform to the spec</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>Type</dt>
<dd>
<span class="param-type">
<a href="ValidationError.html">ValidationError</a>
</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -73,7 +73,7 @@
<h3>Classes</h3><ul><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li></ul>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
@ -119,7 +119,7 @@
</svg>
</a>
<h4 class="name" id="CloudEvent">
<span class="type-signature"></span>new CloudEvent<span class="signature">(UserSpec<span class="signature-attributes">opt</span>, UserFormatter<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span>
<span class="type-signature"></span>new CloudEvent<span class="signature">(userSpec<span class="signature-attributes">opt</span>, userFormatter<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span>
</h4>
</span>
@ -163,7 +163,7 @@
<tr>
<td class="name"><code>UserSpec</code></td>
<td class="name"><code>userSpec</code></td>
<td class="type">
@ -202,7 +202,7 @@
<tr>
<td class="name"><code>UserFormatter</code></td>
<td class="name"><code>userFormatter</code></td>
<td class="type">
@ -397,7 +397,7 @@
<td class="description last">
<p>the name of the exteneion attribute</p>
<p>the name of the extension attribute</p>
</td>
</tr>
@ -843,7 +843,7 @@
<div class="description">
<p>Format the CloudEvent as JSON. Validates the event according
<p>Formats the CloudEvent as JSON. Validates the event according
to the CloudEvent specification and throws an exception if
it's invalid.</p>
</div>

918
docs/HTTPEmitter.html Normal file
View File

@ -0,0 +1,918 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
HTTPEmitter - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
HTTPEmitter
</h1>
<section>
<header>
<h2>
HTTPEmitter
</h2>
<div class="class-description">
<p>A class which is capable of sending binary and structured events using
the CloudEvents HTTP Protocol Binding specification.</p>
</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<span class='name-container'>
<a class="link-icon" href="#HTTPEmitter">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="HTTPEmitter">
<span class="type-signature"></span>new HTTPEmitter<span class="signature">(options<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span>
</h4>
</span>
<div class="description">
<p>Creates a new instance of {HTTPEmitter}. The default emitter uses the 1.0
protocol specification in binary mode.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The configuration options for this event emitter</p>
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>url</code></td>
<td class="type">
<span class="param-type">
URL
</span>
</td>
<td class="attributes">
</td>
<td class="description last">
<p>The endpoint that will receive the sent events.</p>
</td>
</tr>
<tr>
<td class="name"><code>version</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The HTTP binding specification version. Default: &quot;1.0&quot;</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_http_emitter.js.html">bindings/http/http_emitter.js</a>, <a href="bindings_http_http_emitter.js.html#line26">line 26</a>
</li>
</ul>
</dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>
<a href="https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md">https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md</a>
</li>
<li>
<a href="https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md#13-content-modes">https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md#13-content-modes</a>
</li>
</ul>
</dd>
</dl>
<h5>Throws:</h5>
<dl>
<dt>
<div class="param-desc">
<p>if no options.url is provided or an unknown specification version is provided.</p>
</div>
</dt>
<dd></dd>
<dt>
<dl>
<dt>Type</dt>
<dd>
<span class="param-type">
TypeError
</span>
</dd>
</dl>
</dt>
<dd></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<span class='name-container'>
<a class="link-icon" href="#headers">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="headers">
<span class="type-signature"></span>headers<span class="signature">(event)</span><span class="type-signature"> &rarr; {Object}</span>
</h4>
</span>
<div class="description">
<p>Returns the HTTP headers that will be sent for this event when the HTTP transmission
mode is &quot;binary&quot;. Events sent over HTTP in structured mode only have a single CE header
and that is &quot;ce-id&quot;, corresponding to the event ID.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>event</code></td>
<td class="type">
<span class="param-type">
<a href="CloudEvent.html">CloudEvent</a>
</span>
</td>
<td class="description last">
<p>a CloudEvent</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_http_emitter.js.html">bindings/http/http_emitter.js</a>, <a href="bindings_http_http_emitter.js.html#line72">line 72</a>
</li>
</ul>
</dd>
</dl>
<span class='name-container'>
<a class="link-icon" href="#send">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="send">
<span class="type-signature"></span>send<span class="signature">(event, options<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span>
</h4>
</span>
<div class="description">
<p>Sends the {CloudEvent} to an event receiver over HTTP POST</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>event</code></td>
<td class="type">
<span class="param-type">
<a href="CloudEvent.html">CloudEvent</a>
</span>
</td>
<td class="attributes">
</td>
<td class="description last">
<p>the CloudEvent to be sent</p>
</td>
</tr>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The configuration options for this event. Options
provided will be passed along to Node.js <code>http.request()</code>.
https://nodejs.org/api/http.html#http_http_request_options_callback</p>
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>url</code></td>
<td class="type">
<span class="param-type">
URL
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>The HTTP/S url that should receive this event.
The URL is optional if one was provided when this emitter was constructed.
In that case, it will be used as the recipient endpoint. The endpoint can
be overridden by providing a URL here.</p>
</td>
</tr>
<tr>
<td class="name"><code>mode</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>the message mode for sending this event.
Possible values are &quot;binary&quot; and &quot;structured&quot;. Default: structured</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_http_emitter.js.html">bindings/http/http_emitter.js</a>, <a href="bindings_http_http_emitter.js.html#line54">line 54</a>
</li>
</ul>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -73,7 +73,7 @@
<h3>Classes</h3><ul><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li></ul>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
@ -171,7 +171,7 @@
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_http_receiver.js.html">bindings/http/http_receiver.js</a>, <a href="bindings_http_http_receiver.js.html#line21">line 21</a>
<a href="bindings_http_http_receiver.js.html">bindings/http/http_receiver.js</a>, <a href="bindings_http_http_receiver.js.html#line26">line 26</a>
</li>
</ul>
</dd>
@ -371,7 +371,7 @@ binary and structured incoming CloudEvents.</p>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_http_receiver.js.html">bindings/http/http_receiver.js</a>, <a href="bindings_http_http_receiver.js.html#line42">line 42</a>
<a href="bindings_http_http_receiver.js.html">bindings/http/http_receiver.js</a>, <a href="bindings_http_http_receiver.js.html#line47">line 47</a>
</li>
</ul>
</dd>

View File

@ -0,0 +1,472 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
StructuredHTTPEmitter - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
StructuredHTTPEmitter
</h1>
<section>
<header>
<h2>
StructuredHTTPEmitter
</h2>
<div class="class-description">
<p>A class for sending {CloudEvent} instances over HTTP.</p>
</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<span class='name-container'>
<a class="link-icon" href="#StructuredHTTPEmitter">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="StructuredHTTPEmitter">
<span class="type-signature"></span>new StructuredHTTPEmitter<span class="signature">()</span><span class="type-signature"></span>
</h4>
</span>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_emitter_structured.js.html">bindings/http/emitter_structured.js</a>, <a href="bindings_http_emitter_structured.js.html#line19">line 19</a>
</li>
</ul>
</dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<span class='name-container'>
<a class="link-icon" href="#emit">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="emit">
<span class="type-signature">(async) </span>emit<span class="signature">(options, cloudevent)</span><span class="type-signature"> &rarr; {Promise}</span>
</h4>
</span>
<div class="description">
<p>Sends the event over HTTP</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">
Object
</span>
</td>
<td class="description last">
<p>The configuration options for this event. Options
provided will be passed along to Node.js <code>http.request()</code>.
https://nodejs.org/api/http.html#http_http_request_options_callback</p>
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>url</code></td>
<td class="type">
<span class="param-type">
URL
</span>
</td>
<td class="description last">
<p>The HTTP/S url that should receive this event</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="name"><code>cloudevent</code></td>
<td class="type">
<span class="param-type">
<a href="CloudEvent.html">CloudEvent</a>
</span>
</td>
<td class="description last">
<p>The CloudEvent to be sent</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_emitter_structured.js.html">bindings/http/emitter_structured.js</a>, <a href="bindings_http_emitter_structured.js.html#line31">line 31</a>
</li>
</ul>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

352
docs/ValidationError.html Normal file
View File

@ -0,0 +1,352 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
ValidationError - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
ValidationError
</h1>
<section>
<header>
<h2>
ValidationError
</h2>
<div class="class-description">
<p>A Error class that will be thrown when a CloudEvent
cannot be properly validated against a specification.</p>
</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<span class='name-container'>
<a class="link-icon" href="#ValidationError">
<svg height="20" width="20" style="fill: black;">
<use xlink:href="#linkIcon"></use>
</svg>
</a>
<h4 class="name" id="ValidationError">
<span class="type-signature"></span>new ValidationError<span class="signature">(message, errors<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span>
</h4>
</span>
<div class="description">
<p>Constructs a new {ValidationError} with the message
and array of additional errors.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>message</code></td>
<td class="type">
<span class="param-type">
string
</span>
</td>
<td class="attributes">
</td>
<td class="description last">
<p>the error message</p>
</td>
</tr>
<tr>
<td class="name"><code>errors</code></td>
<td class="type">
<span class="param-type">
Array.&lt;string>
</span>
|
<span class="param-type">
Array.&lt;ErrorObject>
</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="description last">
<p>any additional errors related to validation</p>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="bindings_http_validation_validation_error.js.html">bindings/http/validation/validation_error.js</a>, <a href="bindings_http_validation_validation_error.js.html#line12">line 12</a>
</li>
</ul>
</dd>
</dl>
</div>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -0,0 +1,201 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
bindings/http/emitter_binary.js - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
bindings/http/emitter_binary.js
</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const axios = require("axios");
const EmitterV1 = require("./v1").BinaryEmitter;
const EmitterV3 = require("./v03").BinaryEmitter;
const {
HEADERS,
BINARY_HEADERS_03,
BINARY_HEADERS_1,
HEADER_CONTENT_TYPE,
DEFAULT_CONTENT_TYPE,
DATA_ATTRIBUTE,
SPEC_V1,
SPEC_V03
} = require("./constants.js");
const defaults = {
[HEADERS]: {
[HEADER_CONTENT_TYPE]: DEFAULT_CONTENT_TYPE
},
method: "POST"
};
/**
* A class to emit binary CloudEvents over HTTP.
*/
class BinaryHTTPEmitter {
/**
* Create a new {BinaryHTTPEmitter} for the provided CloudEvent specification version.
* Once an instance is created for a given spec version, it may only be used to send
* events for that version.
* Default version is 1.0
* @param {string} version - the CloudEvent HTTP specification version.
* Default: 1.0
*/
constructor(version) {
if (version === SPEC_V1) {
this.headerByGetter = EmitterV1;
this.extensionPrefix = BINARY_HEADERS_1.EXTENSIONS_PREFIX;
} else if (version === SPEC_V03) {
this.headerByGetter = EmitterV3;
this.extensionPrefix = BINARY_HEADERS_03.EXTENSIONS_PREFIX;
}
}
/**
* Sends this cloud event to a receiver over HTTP.
*
* @param {Object} options The configuration options for this event. Options
* provided other than `url` will be passed along to Node.js `http.request`.
* https://nodejs.org/api/http.html#http_http_request_options_callback
* @param {URL} options.url The HTTP/S url that should receive this event
* @param {Object} cloudevent the CloudEvent to be sent
* @returns {Promise} Promise with an eventual response from the receiver
*/
async emit(options, cloudevent) {
const config = { ...options, ...defaults };
const headers = config[HEADERS];
Object.keys(this.headerByGetter)
.filter((getter) => cloudevent[getter]())
.forEach((getter) => {
const header = this.headerByGetter[getter];
headers[header.name] = header.parser(cloudevent[getter]());
});
// Set the cloudevent payload
const formatted = cloudevent.format();
let data = formatted.data;
data = (formatted.data_base64 ? formatted.data_base64 : data);
// Have extensions?
const exts = cloudevent.getExtensions();
Object.keys(exts)
.filter((ext) => Object.hasOwnProperty.call(exts, ext))
.forEach((ext) => {
headers[this.extensionPrefix + ext] = exts[ext];
});
config[DATA_ATTRIBUTE] = data;
config.headers = headers;
// Return the Promise
return axios.request(config);
}
}
module.exports = BinaryHTTPEmitter;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -0,0 +1,152 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
bindings/http/emitter_structured.js - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
bindings/http/emitter_structured.js
</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const axios = require("axios");
const {
DATA_ATTRIBUTE,
DEFAULT_CE_CONTENT_TYPE,
HEADERS,
HEADER_CONTENT_TYPE
} = require("./constants.js");
const defaults = {
[HEADERS]: {
[HEADER_CONTENT_TYPE]: DEFAULT_CE_CONTENT_TYPE
},
method: "POST"
};
/**
* A class for sending {CloudEvent} instances over HTTP.
*/
class StructuredHTTPEmitter {
// TODO: Do we really need a class here? There is no state maintenance
/**
* Sends the event over HTTP
* @param {Object} options The configuration options for this event. Options
* provided will be passed along to Node.js `http.request()`.
* https://nodejs.org/api/http.html#http_http_request_options_callback
* @param {URL} options.url The HTTP/S url that should receive this event
* @param {CloudEvent} cloudevent The CloudEvent to be sent
* @returns {Promise} Promise with an eventual response from the receiver
*/
async emit(options, cloudevent) {
const config = { ...defaults, ...options };
config[DATA_ATTRIBUTE] = cloudevent.format();
return axios.request(config);
}
}
module.exports = StructuredHTTPEmitter;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -0,0 +1,200 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
bindings/http/http_emitter.js - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
bindings/http/http_emitter.js
</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const BinaryHTTPEmitter = require("./emitter_binary.js");
const StructuredEmitter = require("./emitter_structured.js");
const {
SPEC_V03,
SPEC_V1
} = require("./constants");
/**
* A class which is capable of sending binary and structured events using
* the CloudEvents HTTP Protocol Binding specification.
*
* @see https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md
* @see https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md#13-content-modes
*/
class HTTPEmitter {
/**
* Creates a new instance of {HTTPEmitter}. The default emitter uses the 1.0
* protocol specification in binary mode.
*
* @param {Object} [options] The configuration options for this event emitter
* @param {URL} options.url The endpoint that will receive the sent events.
* @param {string} [options.version] The HTTP binding specification version. Default: "1.0"
* @throws {TypeError} if no options.url is provided or an unknown specification version is provided.
*/
constructor({ url, version = SPEC_V1 } = {}) {
if (version !== SPEC_V03 &amp;&amp; version !== SPEC_V1) {
throw new TypeError(
`Unknown CloudEvent specification version: ${version}`);
}
if (!url) {
throw new TypeError("A default endpoint URL is required for a CloudEvent emitter");
}
this.binary = new BinaryHTTPEmitter(version);
this.structured = new StructuredEmitter();
this.url = url;
}
/**
* Sends the {CloudEvent} to an event receiver over HTTP POST
*
* @param {CloudEvent} event the CloudEvent to be sent
* @param {Object} [options] The configuration options for this event. Options
* provided will be passed along to Node.js `http.request()`.
* https://nodejs.org/api/http.html#http_http_request_options_callback
* @param {URL} [options.url] The HTTP/S url that should receive this event.
* The URL is optional if one was provided when this emitter was constructed.
* In that case, it will be used as the recipient endpoint. The endpoint can
* be overridden by providing a URL here.
* @param {string} [options.mode] the message mode for sending this event.
* Possible values are "binary" and "structured". Default: structured
* @returns {Promise} Promise with an eventual response from the receiver
*/
send(event, { url, mode = "binary", ...httpOpts } = {}) {
if (!url) { url = this.url; }
httpOpts.url = url;
if (mode === "binary") {
return this.binary.emit(httpOpts, event);
} else if (mode === "structured") {
return this.structured.emit(httpOpts, event);
}
throw new TypeError(`Unknown transport mode ${mode}.`);
}
/**
* Returns the HTTP headers that will be sent for this event when the HTTP transmission
* mode is "binary". Events sent over HTTP in structured mode only have a single CE header
* and that is "ce-id", corresponding to the event ID.
* @param {CloudEvent} event a CloudEvent
* @returns {Object} the headers that will be sent for the event
*/
headers(event) {
const headers = {};
Object.keys(this.binary.headerByGetter)
.filter((getter) => event[getter]())
.forEach((getter) => {
const header = this.binary.headerByGetter[getter];
headers[header.name] = header.parser(event[getter]());
});
return headers;
}
}
module.exports = HTTPEmitter;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -75,7 +75,7 @@
<h3>Classes</h3><ul><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li></ul>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
@ -90,11 +90,16 @@
<section>
<article>
<pre class="prettyprint source linenums"><code>const V03Binary = require("./receiver_binary_0_3");
const V03Structured = require("./receiver_structured_0_3.js");
const V1Binary = require("./receiver_binary_1.js");
const V1Structured = require("./receiver_structured_1.js");
<pre class="prettyprint source linenums"><code>// const V03Binary = require("./receiver_binary_0_3.js");
// const V03Structured = require("./v03/receiver_structured_0_3.js");
// const V1Binary = require("./receiver_binary_1.js");
// const V1Structured = require("./v1/receiver_structured_1.js");
const BinaryReceiver = require("./receiver_binary.js");
const StructuredReceiver = require("./receiver_structured.js");
const ValidationError = require("./validation/validation_error.js");
const {
BINARY,
STRUCTURED,
SPEC_V03,
SPEC_V1,
HEADER_CONTENT_TYPE,
@ -113,12 +118,12 @@ class HTTPReceiver {
constructor() {
this.receivers = {
v1: {
structured: new V1Structured(),
binary: new V1Binary()
structured: new StructuredReceiver(SPEC_V1),
binary: new BinaryReceiver(SPEC_V1)
},
v03: {
structured: new V03Structured(),
binary: new V03Binary()
structured: new StructuredReceiver(SPEC_V03),
binary: new BinaryReceiver(SPEC_V03)
}
};
}
@ -148,31 +153,29 @@ class HTTPReceiver {
}
function getMode(headers) {
let mode = "unknown";
const contentType = headers[HEADER_CONTENT_TYPE];
if (contentType &amp;&amp; contentType.startsWith(MIME_CE)) {
mode = "structured";
} else if (headers[BINARY_HEADERS_1.ID]) {
mode = "binary";
} else {
throw new TypeError("no cloud event detected");
return STRUCTURED;
}
return mode;
if (headers[BINARY_HEADERS_1.ID]) {
return BINARY;
}
throw new ValidationError("no cloud event detected");
}
function getVersion(mode, headers, body) {
let version = SPEC_V1; // default to 1.0
if (mode === "binary") {
if (mode === BINARY) {
// Check the headers for the version
const versionHeader = headers[DEFAULT_SPEC_VERSION_HEADER];
if (versionHeader) { version = versionHeader; }
if (versionHeader) {
return versionHeader;
}
} else {
// structured mode - the version is in the body
version = body instanceof String
return body instanceof String
? JSON.parse(body).specversion : body.specversion;
}
return version;
return SPEC_V1;
}
module.exports = HTTPReceiver;

View File

@ -0,0 +1,168 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
bindings/http/receiver_binary.js - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
bindings/http/receiver_binary.js
</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const ReceiverV1 = require("./v1/receiver_binary_1.js");
const ReceiverV3 = require("./v03/receiver_binary_0_3.js");
const { SPEC_V03, SPEC_V1 } = require("./constants.js");
const { check, parse } = require("./validation/binary.js");
/**
* A class that receives binary CloudEvents over HTTP. This class can be used
* if you know that all incoming events will be using binary transport. If
* events can come as either binary or structured, use {HTTPReceiver}.
*/
class BinaryHTTPReceiver {
/**
* Creates a new BinaryHTTPReceiver to accept events over HTTP.
*
* @param {string} version the Cloud Event specification version to use. Default "1.0"
*/
constructor(version = SPEC_V1) {
if (version === SPEC_V1) {
this.receiver = new ReceiverV1();
} else if (version === SPEC_V03) {
this.receiver = new ReceiverV3();
}
}
/**
* Checks an incoming HTTP request to determine if it conforms to the
* Cloud Event specification for this receiver.
*
* @throws {ValidationError} if the event does not conform to the spec
* @param {Object} payload the HTTP request body
* @param {Object} headers the HTTP request headers
*
* @returns {void}
*/
check(payload, headers) {
return check(payload, headers, this.receiver);
}
/**
* Parses an incoming HTTP request, converting it to a {CloudEvent}
* instance if it conforms to the Cloud Event specification for this receiver.
*
* @throws {ValidationError} of the event does not conform to the spec
* @param {Object} payload the HTTP request body
* @param {Object} headers the HTTP request headers
* @returns {CloudEvent} an instance of CloudEvent representing the incoming request
*/
parse(payload, headers) {
return parse(payload, headers, this.receiver);
}
}
module.exports = BinaryHTTPReceiver;
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -0,0 +1,131 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
bindings/http/validation/validation_error.js - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
bindings/http/validation/validation_error.js
</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* A Error class that will be thrown when a CloudEvent
* cannot be properly validated against a specification.
*/
class ValidationError extends TypeError {
/**
* Constructs a new {ValidationError} with the message
* and array of additional errors.
* @param {string} message the error message
* @param {string[]|ErrorObject[]} [errors] any additional errors related to validation
*/
constructor(message, errors) {
super(message);
this.errors = errors ? errors : [];
}
}
module.exports = ValidationError;</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -75,7 +75,7 @@
<h3>Classes</h3><ul><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li></ul>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
@ -90,7 +90,7 @@
<section>
<article>
<pre class="prettyprint source linenums"><code>const Spec = require("./specs/spec_1.js");
<pre class="prettyprint source linenums"><code>const Spec = require("./bindings/http/v1/spec_1.js");
const Formatter = require("./formats/json/formatter.js");
/**
@ -99,12 +99,12 @@ const Formatter = require("./formats/json/formatter.js");
class CloudEvent {
/**
* Creates a new CloudEvent instance
* @param {Spec} [UserSpec] A CloudEvent version specification
* @param {Formatter} [UserFormatter] Converts the event into a readable string
* @param {Spec} [userSpec] A CloudEvent version specification
* @param {Formatter} [userFormatter] Converts the event into a readable string
*/
constructor(UserSpec, UserFormatter) {
this.spec = (UserSpec) ? new UserSpec(CloudEvent) : new Spec(CloudEvent);
this.formatter = (UserFormatter) ? new UserFormatter() : new Formatter();
constructor(userSpec, userFormatter) {
this.spec = userSpec ? new userSpec(CloudEvent) : new Spec(CloudEvent);
this.formatter = userFormatter ? new userFormatter() : new Formatter();
// The map of extensions
this.extensions = {};
@ -119,7 +119,7 @@ class CloudEvent {
}
/**
* Format the CloudEvent as JSON. Validates the event according
* Formats the CloudEvent as JSON. Validates the event according
* to the CloudEvent specification and throws an exception if
* it's invalid.
* @returns {JSON} the CloudEvent in JSON form
@ -299,7 +299,7 @@ class CloudEvent {
/**
* Adds an extension attribute to this CloudEvent
* @see https://github.com/cloudevents/spec/blob/master/spec.md#extension-context-attributes
* @param {*} key the name of the exteneion attribute
* @param {*} key the name of the extension attribute
* @param {*} value the value of the extension attribute
* @returns {CloudEvent} this CloudEvent instance
*/

View File

@ -75,7 +75,7 @@
<h3>Classes</h3><ul><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li></ul>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
@ -94,12 +94,11 @@
isString,
isDefinedOrThrow,
isStringOrObjectOrThrow
} = require("../../utils/fun.js");
} = require("../../bindings/http/validation/fun.js");
const ValidationError = require("../../bindings/http/validation/validation_error.js");
const invalidPayloadTypeError =
new Error("invalid payload type, allowed are: string or object");
const nullOrUndefinedPayload =
new Error("null or undefined payload");
const invalidPayloadTypeError = new ValidationError("invalid payload type, allowed are: string or object");
const nullOrUndefinedPayload = new ValidationError("null or undefined payload");
const asJSON = (v) => (isString(v) ? JSON.parse(v) : v);

View File

@ -73,7 +73,7 @@
<h3>Classes</h3><ul><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li></ul>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="BinaryHTTPReceiver-nav"><a href="BinaryHTTPReceiver.html">BinaryHTTPReceiver</a><ul class='methods'><li data-type="method" id="BinaryHTTPReceiver-check-nav"><a href="BinaryHTTPReceiver.html#check">check</a></li><li data-type="method" id="BinaryHTTPReceiver-parse-nav"><a href="BinaryHTTPReceiver.html#parse">parse</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
@ -136,23 +136,57 @@ const receivedEvent = receiver.accept(req.body, req.headers);
console.log(receivedEvent.format());
</code></pre>
<h4>Emitting Events</h4>
<p>Currently, to emit events, you'll need to decide whether the event is in
<p>To emit events, you'll need to decide whether the event should be sent in
binary or structured format, and determine what version of the CloudEvents
specification you want to send the event as.</p>
<pre class="prettyprint source lang-js"><code>const { CloudEvent } = require(&quot;cloudevents-sdk&quot;);
const { StructuredHTTPEmitter } = require(&quot;cloudevents-sdk/v1&quot;);
<p>By default, the <code>HTTPEmitter</code> will emit events over HTTP POST using the
1.0 specification, in binary mode. You can emit 0.3 events by providing
the specication version in the constructor to <code>HTTPEmitter</code>. To send
structured events, add that string as a parameter to <code>emitter.sent()</code>.</p>
<pre class="prettyprint source lang-js"><code>const { CloudEvent, HTTPEmitter } = require(&quot;cloudevents-sdk&quot;);
const myevent = new CloudEvent()
.type(&quot;com.github.pull.create&quot;)
.source(&quot;urn:event:from:myapi/resource/123&quot;);
// With only an endpoint URL, this creates a v1 emitter
const v1Emitter = new HTTPEmitter({
url: &quot;https://cloudevents.io/example&quot;
});
const event = new CloudEvent()
.type(type)
.source(source)
.time(new Date())
.data(data)
const emitter = new StructuredHTTPEmitter({
method: &quot;POST&quot;,
url : &quot;https://myserver.com&quot;
// By default, the emitter will send binary events
v1Emitter.send(event).then((response) => {
// handle the response
}).catch(console.error);
// To send a structured event, just add that as an option
v1Emitter.send(event, { mode: &quot;structured&quot; })
.then((response) => {
// handle the response
}).catch(console.error);
// To send an event to an alternate URL, add that as an option
v1Emitter.send(event, { url: &quot;https://alternate.com/api&quot; })
.then((response) => {
// handle the response
}).catch(console.error);
// Sending a v0.3 event works the same, just let the emitter know when
// you create it that you are working with the 0.3 spec
const v03Emitter = new HTTPEmitter({
url: &quot;https://cloudevents.io/example&quot;,
version: &quot;0.3&quot;
});
// Emit the event
emitter.emit(myevent)
// Again, the default is to send binary events
// To send a structured event or to an alternate URL, provide those
// as parameters in a options object as above
v3Emitter.send(event)
.then((response) => {
// handle the response
}).catch(console.error);
</code></pre>
<h2>Supported specification features</h2>
<table>

View File

@ -0,0 +1,131 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
validation_error.js - Documentation
</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li >
<a href="index.html">
<svg fill="#6D6D6D" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
cloudevents-sdk
</h3>
<h3>
Resources
</h3>
<a href="concepts.html">Concepts</a>
<h3>Classes</h3><ul><li id="BinaryHTTPEmitter-nav"><a href="BinaryHTTPEmitter.html">BinaryHTTPEmitter</a><ul class='methods'><li data-type="method" id="BinaryHTTPEmitter-emit-nav"><a href="BinaryHTTPEmitter.html#emit">emit</a></li></ul></li><li id="CloudEvent-nav"><a href="CloudEvent.html">CloudEvent</a><ul class='methods'><li data-type="method" id="CloudEvent-addExtension-nav"><a href="CloudEvent.html#addExtension">addExtension</a></li><li data-type="method" id="CloudEvent-data-nav"><a href="CloudEvent.html#data">data</a></li><li data-type="method" id="CloudEvent-dataContenttype-nav"><a href="CloudEvent.html#dataContenttype">dataContenttype</a></li><li data-type="method" id="CloudEvent-format-nav"><a href="CloudEvent.html#format">format</a></li><li data-type="method" id="CloudEvent-getData-nav"><a href="CloudEvent.html#getData">getData</a></li><li data-type="method" id="CloudEvent-getDataContenttype-nav"><a href="CloudEvent.html#getDataContenttype">getDataContenttype</a></li><li data-type="method" id="CloudEvent-getExtensions-nav"><a href="CloudEvent.html#getExtensions">getExtensions</a></li><li data-type="method" id="CloudEvent-getFormats-nav"><a href="CloudEvent.html#getFormats">getFormats</a></li><li data-type="method" id="CloudEvent-getId-nav"><a href="CloudEvent.html#getId">getId</a></li><li data-type="method" id="CloudEvent-getSource-nav"><a href="CloudEvent.html#getSource">getSource</a></li><li data-type="method" id="CloudEvent-getSpecversion-nav"><a href="CloudEvent.html#getSpecversion">getSpecversion</a></li><li data-type="method" id="CloudEvent-getTime-nav"><a href="CloudEvent.html#getTime">getTime</a></li><li data-type="method" id="CloudEvent-getType-nav"><a href="CloudEvent.html#getType">getType</a></li><li data-type="method" id="CloudEvent-id-nav"><a href="CloudEvent.html#id">id</a></li><li data-type="method" id="CloudEvent-source-nav"><a href="CloudEvent.html#source">source</a></li><li data-type="method" id="CloudEvent-time-nav"><a href="CloudEvent.html#time">time</a></li><li data-type="method" id="CloudEvent-toString-nav"><a href="CloudEvent.html#toString">toString</a></li><li data-type="method" id="CloudEvent-type-nav"><a href="CloudEvent.html#type">type</a></li></ul></li><li id="HTTPEmitter-nav"><a href="HTTPEmitter.html">HTTPEmitter</a><ul class='methods'><li data-type="method" id="HTTPEmitter-headers-nav"><a href="HTTPEmitter.html#headers">headers</a></li><li data-type="method" id="HTTPEmitter-send-nav"><a href="HTTPEmitter.html#send">send</a></li></ul></li><li id="HTTPReceiver-nav"><a href="HTTPReceiver.html">HTTPReceiver</a><ul class='methods'><li data-type="method" id="HTTPReceiver-accept-nav"><a href="HTTPReceiver.html#accept">accept</a></li></ul></li><li id="StructuredHTTPEmitter-nav"><a href="StructuredHTTPEmitter.html">StructuredHTTPEmitter</a><ul class='methods'><li data-type="method" id="StructuredHTTPEmitter-emit-nav"><a href="StructuredHTTPEmitter.html#emit">emit</a></li></ul></li><li id="ValidationError-nav"><a href="ValidationError.html">ValidationError</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">
validation_error.js
</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* A Error class that will be thrown when a CloudEvent
* cannot be properly validated against a the specification.
*/
class ValidationError extends TypeError {
/**
* Constructs a new {ValidationError} with the message
* and array of additional errors.
* @param {string} message the error message
* @param {string[]|ErrorObject[]} [errors] any additional errors related to validation
*/
constructor(message, errors) {
super(message);
this.errors = errors ? errors : [];
}
}
module.exports = ValidationError;</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.4</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>

View File

@ -1,4 +1,6 @@
const axios = require("axios");
const EmitterV1 = require("./v1").BinaryEmitter;
const EmitterV3 = require("./v03").BinaryEmitter;
const {
HEADERS,
@ -32,10 +34,10 @@ class BinaryHTTPEmitter {
*/
constructor(version) {
if (version === SPEC_V1) {
this.headerByGetter = require("./emitter_binary_1.js");
this.headerByGetter = EmitterV1;
this.extensionPrefix = BINARY_HEADERS_1.EXTENSIONS_PREFIX;
} else if (version === SPEC_V03) {
this.headerByGetter = require("./emitter_binary_0_3.js");
this.headerByGetter = EmitterV3;
this.extensionPrefix = BINARY_HEADERS_03.EXTENSIONS_PREFIX;
}
}

View File

@ -1,8 +1,10 @@
const V03Binary = require("./receiver_binary_0_3.js");
const V03Structured = require("./receiver_structured_0_3.js");
const V1Binary = require("./receiver_binary_1.js");
const V1Structured = require("./receiver_structured_1.js");
const ValidationError = require("../../validation_error.js");
// const V03Binary = require("./receiver_binary_0_3.js");
// const V03Structured = require("./v03/receiver_structured_0_3.js");
// const V1Binary = require("./receiver_binary_1.js");
// const V1Structured = require("./v1/receiver_structured_1.js");
const BinaryReceiver = require("./receiver_binary.js");
const StructuredReceiver = require("./receiver_structured.js");
const ValidationError = require("./validation/validation_error.js");
const {
BINARY,
STRUCTURED,
@ -24,12 +26,12 @@ class HTTPReceiver {
constructor() {
this.receivers = {
v1: {
structured: new V1Structured(),
binary: new V1Binary()
structured: new StructuredReceiver(SPEC_V1),
binary: new BinaryReceiver(SPEC_V1)
},
v03: {
structured: new V03Structured(),
binary: new V03Binary()
structured: new StructuredReceiver(SPEC_V03),
binary: new BinaryReceiver(SPEC_V03)
}
};
}

View File

@ -1,134 +1,54 @@
const { HEADER_CONTENT_TYPE, MIME_JSON, DEFAULT_SPEC_VERSION_HEADER } =
require("./constants.js");
const Commons = require("./commons.js");
const CloudEvent = require("../../cloudevent.js");
const ValidationError = require("../../validation_error.js");
const ReceiverV1 = require("./v1/receiver_binary_1.js");
const ReceiverV3 = require("./v03/receiver_binary_0_3.js");
const {
isDefinedOrThrow,
isStringOrObjectOrThrow
} = require("../../utils/fun.js");
const { SPEC_V03, SPEC_V1 } = require("./constants.js");
const { check, parse } = require("./validation/binary.js");
function validateArgs(payload, attributes) {
Array.of(payload)
.filter((p) => isDefinedOrThrow(p, new ValidationError("payload is null or undefined")))
.filter((p) => isStringOrObjectOrThrow(p, new ValidationError("payload must be an object or a string")))
.shift();
Array.of(attributes)
.filter((a) => isDefinedOrThrow(a, new ValidationError("attributes is null or undefined")))
.shift();
/**
* A class that receives binary CloudEvents over HTTP. This class can be used
* if you know that all incoming events will be using binary transport. If
* events can come as either binary or structured, use {HTTPReceiver}.
*/
class BinaryHTTPReceiver {
/**
* Creates a new BinaryHTTPReceiver to accept events over HTTP.
*
* @param {string} version the Cloud Event specification version to use. Default "1.0"
*/
constructor(version = SPEC_V1) {
if (version === SPEC_V1) {
this.receiver = new ReceiverV1();
} else if (version === SPEC_V03) {
this.receiver = new ReceiverV3();
}
}
function BinaryHTTPReceiver(
parsersByEncoding,
setterByHeader,
allowedContentTypes,
requiredHeaders,
Spec,
specversion,
extensionsPrefix,
checkDecorator) {
this.parsersByEncoding = parsersByEncoding;
this.setterByHeader = setterByHeader;
this.allowedContentTypes = allowedContentTypes;
this.requiredHeaders = requiredHeaders;
this.Spec = Spec;
this.spec = new Spec();
this.specversion = specversion;
this.extensionsPrefix = extensionsPrefix;
this.checkDecorator = checkDecorator;
/**
* Checks an incoming HTTP request to determine if it conforms to the
* Cloud Event specification for this receiver.
*
* @throws {ValidationError} if the event does not conform to the spec
* @param {Object} payload the HTTP request body
* @param {Object} headers the HTTP request headers
*
* @returns {void}
*/
check(payload, headers) {
return check(payload, headers, this.receiver);
}
BinaryHTTPReceiver.prototype.check = function(payload, headers) {
// Validation Level 0
validateArgs(payload, headers);
if (this.checkDecorator) {
this.checkDecorator(payload, headers);
/**
* Parses an incoming HTTP request, converting it to a {CloudEvent}
* instance if it conforms to the Cloud Event specification for this receiver.
*
* @throws {ValidationError} of the event does not conform to the spec
* @param {Object} payload the HTTP request body
* @param {Object} headers the HTTP request headers
* @returns {CloudEvent} an instance of CloudEvent representing the incoming request
*/
parse(payload, headers) {
return parse(payload, headers, this.receiver);
}
// Clone and low case all headers names
const sanityHeaders = Commons.sanityAndClone(headers);
// Validation Level 1 - if content-type exists, be sure it's
// an allowed type
const contentTypeHeader = sanityHeaders[HEADER_CONTENT_TYPE];
const noContentType = !this.allowedContentTypes.includes(contentTypeHeader);
if (contentTypeHeader && noContentType) {
throw new ValidationError("invalid content type", [sanityHeaders[HEADER_CONTENT_TYPE]]);
}
this.requiredHeaders
.filter((required) => !sanityHeaders[required])
.forEach((required) => {
throw new ValidationError(`header '${required}' not found`);
});
if (sanityHeaders[DEFAULT_SPEC_VERSION_HEADER] !==
this.specversion) {
throw new ValidationError("invalid spec version", [sanityHeaders[DEFAULT_SPEC_VERSION_HEADER]]);
}
// No erros! Its contains the minimum required attributes
};
function parserFor(parsersByEncoding, cloudevent, headers) {
const encoding = cloudevent.spec.payload.datacontentencoding;
return parsersByEncoding[encoding][headers[HEADER_CONTENT_TYPE]];
}
BinaryHTTPReceiver.prototype.parse = function(payload, headers) {
this.check(payload, headers);
// Clone and low case all headers names
const sanityHeaders = Commons.sanityAndClone(headers);
if (!sanityHeaders[HEADER_CONTENT_TYPE]) {
sanityHeaders[HEADER_CONTENT_TYPE] = MIME_JSON;
}
const processedHeaders = [];
const cloudevent = new CloudEvent(this.Spec);
// dont worry, check() have seen what was required or not
Array.from(Object.keys(this.setterByHeader))
.filter((header) => sanityHeaders[header])
.forEach((header) => {
const setterName = this.setterByHeader[header].name;
const parserFun = this.setterByHeader[header].parser;
// invoke the setter function
cloudevent[setterName](parserFun(sanityHeaders[header]));
// to use ahead, for extensions processing
processedHeaders.push(header);
});
// Parses the payload
const parsedPayload =
parserFor(this.parsersByEncoding, cloudevent, sanityHeaders)
.parse(payload);
// Every unprocessed header can be an extension
Array.from(Object.keys(sanityHeaders))
.filter((value) => !processedHeaders.includes(value))
.filter((value) =>
value.startsWith(this.extensionsPrefix))
.map((extension) =>
extension.substring(this.extensionsPrefix.length)
).forEach((extension) =>
cloudevent.addExtension(extension,
sanityHeaders[this.extensionsPrefix + extension])
);
// Sets the data
cloudevent.data(parsedPayload);
// Checks the event spec
cloudevent.format();
// return the result
return cloudevent;
};
module.exports = BinaryHTTPReceiver;

View File

@ -1,119 +0,0 @@
const Constants = require("./constants.js");
const Spec = require("../../specs/spec_0_3.js");
const ValidationError = require("../../validation_error.js");
const JSONParser = require("../../formats/json/parser.js");
const Base64Parser = require("../../formats/base64.js");
const BinaryHTTPReceiver = require("./receiver_binary.js");
const parserByType = {};
parserByType[Constants.MIME_JSON] = new JSONParser();
parserByType[Constants.MIME_OCTET_STREAM] = {
parse(payload) { return payload; }
};
const parsersByEncoding = {};
parsersByEncoding.null = parserByType;
parsersByEncoding[undefined] = parserByType;
// base64
parsersByEncoding[Constants.ENCODING_BASE64] = {};
parsersByEncoding[Constants.ENCODING_BASE64][Constants.MIME_JSON] =
new JSONParser(new Base64Parser());
parsersByEncoding[Constants.ENCODING_BASE64][Constants.MIME_OCTET_STREAM] = {
parse(payload) { return payload; }
};
const allowedContentTypes = [];
allowedContentTypes.push(Constants.MIME_JSON);
allowedContentTypes.push(Constants.MIME_OCTET_STREAM);
const allowedEncodings = [];
allowedEncodings.push(Constants.ENCODING_BASE64);
const requiredHeaders = [];
requiredHeaders.push(Constants.BINARY_HEADERS_03.TYPE);
requiredHeaders.push(Constants.BINARY_HEADERS_03.SPEC_VERSION);
requiredHeaders.push(Constants.BINARY_HEADERS_03.SOURCE);
requiredHeaders.push(Constants.BINARY_HEADERS_03.ID);
const setterByHeader = {};
setterByHeader[Constants.BINARY_HEADERS_03.TYPE] = {
name: "type",
parser: (v) => v
};
setterByHeader[Constants.BINARY_HEADERS_03.SPEC_VERSION] = {
name: "specversion",
parser: () => "0.3"
};
setterByHeader[Constants.BINARY_HEADERS_03.SOURCE] = {
name: "source",
parser: (v) => v
};
setterByHeader[Constants.BINARY_HEADERS_03.ID] = {
name: "id",
parser: (v) => v
};
setterByHeader[Constants.BINARY_HEADERS_03.TIME] = {
name: "time",
parser: (v) => new Date(Date.parse(v))
};
setterByHeader[Constants.BINARY_HEADERS_03.SCHEMA_URL] = {
name: "schemaurl",
parser: (v) => v
};
setterByHeader[Constants.HEADER_CONTENT_TYPE] = {
name: "dataContentType",
parser: (v) => v
};
setterByHeader[Constants.BINARY_HEADERS_03.CONTENT_ENCODING] = {
name: "dataContentEncoding",
parser: (v) => v
};
setterByHeader[Constants.BINARY_HEADERS_03.SUBJECT] = {
name: "subject",
parser: (v) => v
};
// Leaving this in place for now. TODO: fixme
// eslint-disable-next-line
function checkDecorator(payload, headers) {
Object.keys(headers)
.map((header) => header.toLocaleLowerCase("en-US"))
.filter((header) =>
header === Constants.BINARY_HEADERS_03.CONTENT_ENCODING)
.filter((header) => !allowedEncodings.includes(headers[header]))
.forEach((header) => {
// TODO: using forEach here seems off
throw new ValidationError("unsupported datacontentencoding");
});
}
// Leaving this in place for now. TODO: fixme
// eslint-disable-next-line
function Receiver(configuration) {
this.receiver = new BinaryHTTPReceiver(
parsersByEncoding,
setterByHeader,
allowedContentTypes,
requiredHeaders,
Spec,
Constants.SPEC_V03,
Constants.BINARY_HEADERS_03.EXTENSIONS_PREFIX,
checkDecorator
);
}
Receiver.prototype.check = function(payload, headers) {
this.receiver.check(payload, headers);
};
Receiver.prototype.parse = function(payload, headers) {
// firstly specific local checks
this.check(payload, headers);
return this.receiver.parse(payload, headers);
};
module.exports = Receiver;

View File

@ -1,78 +0,0 @@
const {
MIME_JSON,
MIME_OCTET_STREAM,
ENCODING_BASE64,
BINARY_HEADERS_1,
HEADER_CONTENT_TYPE,
SPEC_V1
} = require("./constants.js");
const Spec = require("../../specs/spec_1.js");
const JSONParser = require("../../formats/json/parser.js");
const Base64Parser = require("../../formats/base64.js");
const BinaryHTTPReceiver = require("./receiver_binary.js");
const {
isString,
isBase64
} = require("../../utils/fun.js");
const parserByType = {
[MIME_JSON] : new JSONParser(),
[MIME_OCTET_STREAM] : { parse(payload) { return payload; } }
};
const parsersByEncoding = { [null] : parserByType, [undefined] : parserByType, [ENCODING_BASE64] : {} };
parsersByEncoding[ENCODING_BASE64][MIME_JSON] = new JSONParser(new Base64Parser());
parsersByEncoding[ENCODING_BASE64][MIME_OCTET_STREAM] = {
parse(payload) { return payload; }
};
const allowedContentTypes = [MIME_JSON, MIME_OCTET_STREAM];
const requiredHeaders = [BINARY_HEADERS_1.TYPE, BINARY_HEADERS_1.SPEC_VERSION,
BINARY_HEADERS_1.SOURCE, BINARY_HEADERS_1.ID];
const setterByHeader = {
[BINARY_HEADERS_1.TYPE] : { name: "type", parser: (v) => v },
[BINARY_HEADERS_1.SPEC_VERSION] : { name: "specversion", parser: () => "1.0" },
[BINARY_HEADERS_1.SOURCE] : { name: "source", parser: (v) => v },
[BINARY_HEADERS_1.ID] : { name: "id", parser: (v) => v },
[BINARY_HEADERS_1.TIME] : { name: "time", parser: (v) => new Date(Date.parse(v)) },
[BINARY_HEADERS_1.DATA_SCHEMA] : { name: "dataschema", parser: (v) => v },
[HEADER_CONTENT_TYPE] : { name: "dataContentType", parser: (v) => v },
[BINARY_HEADERS_1.SUBJECT] : { name: "subject", parser: (v) => v }
};
// Leaving these in place for now. TODO: fixme
// eslint-disable-next-line
function checkDecorator(payload, headers) {}
// Leaving this in place for now. TODO: fixme
// eslint-disable-next-line
function Receiver(configuration) {
this.receiver = new BinaryHTTPReceiver(
parsersByEncoding,
setterByHeader,
allowedContentTypes,
requiredHeaders,
Spec,
SPEC_V1,
BINARY_HEADERS_1.EXTENSIONS_PREFIX,
checkDecorator
);
}
Receiver.prototype.check = function(payload, headers) {
this.receiver.check(payload, headers);
};
Receiver.prototype.parse = function(payload, headers) {
payload = isString(payload) && isBase64(payload)
? Buffer.from(payload, "base64").toString()
: payload;
return this.receiver.parse(payload, headers);
};
module.exports = Receiver;

View File

@ -1,82 +1,25 @@
const Constants = require("./constants.js");
const Commons = require("./commons.js");
const CloudEvent = require("../../cloudevent.js");
const ValidationError = require("../../validation_error.js");
const ReceiverV1 = require("./v1/receiver_structured_1.js");
const ReceiverV3 = require("./v03/receiver_structured_0_3.js");
const {
isDefinedOrThrow,
isStringOrObjectOrThrow
} = require("../../utils/fun.js");
const { SPEC_V03, SPEC_V1 } = require("./constants.js");
const { check, parse } = require("./validation/structured.js");
function validateArgs(payload, attributes) {
Array.of(payload)
.filter((p) => isDefinedOrThrow(p, new ValidationError("payload is null or undefined")))
.filter((p) => isStringOrObjectOrThrow(p, new ValidationError("payload must be an object or string")))
.shift();
Array.of(attributes)
.filter((a) => isDefinedOrThrow(a, new ValidationError("attributes is null or undefined")))
.shift();
class StructuredHTTPReceiver {
constructor(version = SPEC_V1) {
if (version === SPEC_V1) {
this.receiver = new ReceiverV1();
} else if (version === SPEC_V03) {
this.receiver = new ReceiverV3();
}
}
function StructuredHTTPReceiver(
parserByMime,
parserMap,
allowedContentTypes,
Spec) {
this.parserByMime = parserByMime;
this.parserMap = parserMap;
this.allowedContentTypes = allowedContentTypes;
this.Spec = Spec;
this.spec = new Spec();
check(payload, headers) {
return check(payload, headers, this.receiver);
}
StructuredHTTPReceiver.prototype.check = function(payload, headers) {
validateArgs(payload, headers);
const sanityHeaders = Commons.sanityAndClone(headers);
// Validation Level 1
if (!this.allowedContentTypes
.includes(sanityHeaders[Constants.HEADER_CONTENT_TYPE])) {
throw new ValidationError("invalid content type", [sanityHeaders[Constants.HEADER_CONTENT_TYPE]]);
parse(payload, headers) {
return parse(payload, headers, this.receiver);
}
// No erros! Its contains the minimum required attributes
};
StructuredHTTPReceiver.prototype.parse = function(payload, headers) {
this.check(payload, headers);
const sanityHeaders = Commons.sanityAndClone(headers);
const contentType = sanityHeaders[Constants.HEADER_CONTENT_TYPE];
const parser = this.parserByMime[contentType];
const event = parser.parse(payload);
this.spec.check(event);
const processedAttributes = [];
const cloudevent = new CloudEvent(this.Spec);
this.parserMap.forEach((value, key) => {
if (event[key]) {
// invoke the setter function
cloudevent[value.name](value.parser(event[key]));
// to use ahead, for extensions processing
processedAttributes.push(key);
}
});
// Every unprocessed attribute should be an extension
Array.from(Object.keys(event))
.filter((attribute) => !processedAttributes.includes(attribute))
.forEach((extension) =>
cloudevent.addExtension(extension, event[extension])
);
return cloudevent;
};
module.exports = StructuredHTTPReceiver;

View File

@ -1,76 +0,0 @@
const {
HEADER_CONTENT_TYPE,
MIME_CE,
MIME_CE_JSON,
MIME_JSON,
MIME_OCTET_STREAM,
BINARY,
STRUCTURED
} = require("./constants.js");
const Commons = require("./commons.js");
const ValidationError = require("../../validation_error.js");
const allowedBinaryContentTypes = [
MIME_JSON,
MIME_OCTET_STREAM
];
const allowedStructuredContentTypes = [
MIME_CE_JSON
];
// Is it binary or structured?
function resolveBindingName(payload, headers) {
const contentType =
Commons.sanityContentType(headers[HEADER_CONTENT_TYPE]);
if (contentType.startsWith(MIME_CE)) {
// Structured
if (allowedStructuredContentTypes.includes(contentType)) {
return STRUCTURED;
}
throwValidationError("structured+type not allowed", contentType);
} else {
// Binary
if (allowedBinaryContentTypes.includes(contentType)) {
return BINARY;
}
throwValidationError("content type not allowed", contentType);
}
}
function throwValidationError(msg, contentType) {
const err = new ValidationError(msg);
err.errors = [contentType];
throw err;
}
class Unmarshaller {
constructor(receiverByBinding) {
this.receiverByBinding = receiverByBinding;
}
unmarshall(payload, headers) {
if (!payload) {
throw new ValidationError("payload is null or undefined");
}
if (!headers) {
throw new ValidationError("headers is null or undefined");
}
// Validation level 1
const sanityHeaders = Commons.sanityAndClone(headers);
if (!sanityHeaders[HEADER_CONTENT_TYPE]) {
throw new ValidationError("content-type header not found");
}
// Resolve the binding
const bindingName = resolveBindingName(payload, sanityHeaders);
const cloudevent = this.receiverByBinding[bindingName]
.parse(payload, sanityHeaders);
return cloudevent;
}
}
module.exports = Unmarshaller;

View File

@ -1,19 +0,0 @@
const GenericUnmarshaller = require("./unmarshaller.js");
const StructuredReceiver = require("./receiver_structured_0_3.js");
const BinaryReceiver = require("./receiver_binary_0_3.js");
const RECEIVER_BY_BINDING = {
structured: new StructuredReceiver(),
binary: new BinaryReceiver()
};
const Unmarshaller = function() {
this.unmarshaller = new GenericUnmarshaller(RECEIVER_BY_BINDING);
};
Unmarshaller.prototype.unmarshall = function(payload, headers) {
return this.unmarshaller.unmarshall(payload, headers);
};
module.exports = Unmarshaller;

View File

@ -1,7 +1,7 @@
const {
HEADER_CONTENT_TYPE,
BINARY_HEADERS_03
} = require("./constants.js");
} = require("../constants.js");
const headerByGetter = {};

View File

@ -0,0 +1,9 @@
const Spec = require("./spec_0_3.js");
const BinaryEmitter = require("./emitter_binary_0_3.js");
const StructuredEmitter = require("./receiver_structured_0_3.js");
module.exports = {
Spec,
BinaryEmitter,
StructuredEmitter
};

View File

@ -0,0 +1,96 @@
const {
SPEC_V03,
MIME_JSON,
MIME_OCTET_STREAM,
ENCODING_BASE64,
HEADER_CONTENT_TYPE,
BINARY_HEADERS_03
} = require("../constants.js");
const Spec = require("./spec_0_3.js");
const JSONParser = require("../../../formats/json/parser.js");
const Base64Parser = require("../../../formats/base64.js");
const parserByType = {
[MIME_JSON]: new JSONParser(),
[MIME_OCTET_STREAM]: {
parse(payload) { return payload; }
}
};
const parsersByEncoding = {
null: parserByType,
undefined: parserByType
};
// base64
parsersByEncoding[ENCODING_BASE64] = {
[MIME_JSON]: new JSONParser(new Base64Parser()),
[MIME_OCTET_STREAM]: {
parse(payload) { return payload; }
}
};
const allowedContentTypes = [
MIME_JSON, MIME_OCTET_STREAM
];
const requiredHeaders = [
BINARY_HEADERS_03.TYPE,
BINARY_HEADERS_03.SPEC_VERSION,
BINARY_HEADERS_03.SOURCE,
BINARY_HEADERS_03.ID
];
const setterByHeader = {};
setterByHeader[BINARY_HEADERS_03.TYPE] = {
name: "type",
parser: (v) => v
};
setterByHeader[BINARY_HEADERS_03.SPEC_VERSION] = {
name: "specversion",
parser: () => "0.3"
};
setterByHeader[BINARY_HEADERS_03.SOURCE] = {
name: "source",
parser: (v) => v
};
setterByHeader[BINARY_HEADERS_03.ID] = {
name: "id",
parser: (v) => v
};
setterByHeader[BINARY_HEADERS_03.TIME] = {
name: "time",
parser: (v) => new Date(Date.parse(v))
};
setterByHeader[BINARY_HEADERS_03.SCHEMA_URL] = {
name: "schemaurl",
parser: (v) => v
};
setterByHeader[HEADER_CONTENT_TYPE] = {
name: "dataContentType",
parser: (v) => v
};
setterByHeader[BINARY_HEADERS_03.CONTENT_ENCONDING] = {
name: "dataContentEncoding",
parser: (v) => v
};
setterByHeader[BINARY_HEADERS_03.SUBJECT] = {
name: "subject",
parser: (v) => v
};
class Receiver {
constructor() {
this.parsersByEncoding = parsersByEncoding;
this.setterByHeader = setterByHeader;
this.allowedContentTypes = allowedContentTypes;
this.requiredHeaders = requiredHeaders;
this.extensionsPrefix = BINARY_HEADERS_03.EXTENSIONS_PREFIX;
this.specversion = SPEC_V03;
this.Spec = Spec;
this.spec = new Spec();
}
}
module.exports = Receiver;

View File

@ -13,21 +13,19 @@ const {
SUBJECT,
DATA
}
} = require("./constants.js");
const Constants = require("./constants.js");
const Spec = require("../../specs/spec_0_3.js");
const JSONParser = require("../../formats/json/parser.js");
const StructuredHTTPReceiver = require("./receiver_structured.js");
} = require("../constants.js");
const Spec = require("./spec_0_3.js");
const JSONParser = require("../../../formats/json/parser.js");
const jsonParserSpec = new JSONParser();
const parserByMime = {
[MIME_JSON]: jsonParserSpec,
[MIME_CE_JSON]: jsonParserSpec
};
const parserByMime = {};
parserByMime[MIME_JSON] = jsonParserSpec;
parserByMime[MIME_CE_JSON] = jsonParserSpec;
const allowedContentTypes = [];
allowedContentTypes.push(MIME_CE_JSON);
const allowedContentTypes = [
MIME_CE_JSON
];
function parser(name, parser = (v) => v) {
return { name: name, parser: parser};
@ -46,23 +44,14 @@ parserMap.set(CONTENT_TYPE, passThroughParser("dataContentType"));
parserMap.set(SUBJECT, passThroughParser("subject"));
parserMap.set(DATA, passThroughParser("data"));
// Leaving this in place for now. TODO: fixme
// eslint-disable-next-line
function Receiver(configuration) {
this.receiver = new StructuredHTTPReceiver(
parserByMime,
parserMap,
allowedContentTypes,
Spec
);
class Receiver {
constructor() {
this.parserByMime = parserByMime;
this.parserMap = parserMap;
this.allowedContentTypes = allowedContentTypes;
this.Spec = Spec;
this.spec = new Spec();
}
}
Receiver.prototype.check = function(payload, headers) {
this.receiver.check(payload, headers);
};
Receiver.prototype.parse = function(payload, headers) {
return this.receiver.parse(payload, headers);
};
module.exports = Receiver;

View File

@ -1,12 +1,12 @@
const { v4: uuidv4 } = require("uuid");
const Ajv = require("ajv");
const ValidationError = require("../validation_error.js");
const ValidationError = require("../validation/validation_error.js");
const {
isBase64,
clone,
asData
} = require("../utils/fun.js");
} = require("../validation/fun.js");
const RESERVED_ATTRIBUTES = {
type: "type",
@ -126,7 +126,7 @@ function Spec03(_caller) {
};
if (!_caller) {
_caller = require("../cloudevent.js");
_caller = require("../../../cloudevent.js");
}
/*

View File

@ -1,7 +1,7 @@
const {
HEADER_CONTENT_TYPE,
BINARY_HEADERS_1
} = require("./constants.js");
} = require("../constants.js");
const headerByGetter = {};

View File

@ -0,0 +1,9 @@
const Spec = require("./spec_1.js");
const BinaryEmitter = require("./emitter_binary_1.js");
const StructuredEmitter = require("./receiver_structured_1.js");
module.exports = {
Spec,
BinaryEmitter,
StructuredEmitter
};

View File

@ -0,0 +1,55 @@
const {
SPEC_V1,
MIME_JSON,
MIME_OCTET_STREAM,
ENCODING_BASE64,
BINARY_HEADERS_1,
HEADER_CONTENT_TYPE
} = require("../constants.js");
const Spec = require("./spec_1.js");
const JSONParser = require("../../../formats/json/parser.js");
const Base64Parser = require("../../../formats/base64.js");
const parserByType = {
[MIME_JSON] : new JSONParser(),
[MIME_OCTET_STREAM] : { parse(payload) { return payload; } }
};
const parsersByEncoding = { [null] : parserByType, [undefined] : parserByType, [ENCODING_BASE64] : {} };
parsersByEncoding[ENCODING_BASE64][MIME_JSON] = new JSONParser(new Base64Parser());
parsersByEncoding[ENCODING_BASE64][MIME_OCTET_STREAM] = {
parse(payload) { return payload; }
};
const allowedContentTypes = [MIME_JSON, MIME_OCTET_STREAM];
const requiredHeaders = [BINARY_HEADERS_1.TYPE, BINARY_HEADERS_1.SPEC_VERSION,
BINARY_HEADERS_1.SOURCE, BINARY_HEADERS_1.ID];
const setterByHeader = {
[BINARY_HEADERS_1.TYPE] : { name: "type", parser: (v) => v },
[BINARY_HEADERS_1.SPEC_VERSION] : { name: "specversion", parser: () => "1.0" },
[BINARY_HEADERS_1.SOURCE] : { name: "source", parser: (v) => v },
[BINARY_HEADERS_1.ID] : { name: "id", parser: (v) => v },
[BINARY_HEADERS_1.TIME] : { name: "time", parser: (v) => new Date(Date.parse(v)) },
[BINARY_HEADERS_1.DATA_SCHEMA] : { name: "dataschema", parser: (v) => v },
[HEADER_CONTENT_TYPE] : { name: "dataContentType", parser: (v) => v },
[BINARY_HEADERS_1.SUBJECT] : { name: "subject", parser: (v) => v }
};
class Receiver {
constructor() {
this.parserByType = parserByType;
this.parsersByEncoding = parsersByEncoding;
this.allowedContentTypes = allowedContentTypes;
this.requiredHeaders = requiredHeaders;
this.setterByHeader = setterByHeader;
this.specversion = SPEC_V1;
this.extensionsPrefix = BINARY_HEADERS_1.EXTENSIONS_PREFIX;
this.Spec = Spec;
this.spec = new Spec();
}
}
module.exports = Receiver;

View File

@ -1,5 +1,4 @@
const {
MIME_JSON,
MIME_CE_JSON,
STRUCTURED_ATTRS_1 : {
TYPE,
@ -11,23 +10,22 @@ const {
CONTENT_TYPE,
SUBJECT,
DATA,
DATA_BASE64
DATA_BASE64,
MIME_JSON
}
} = require("./constants.js");
} = require("../constants.js");
const Spec = require("../../specs/spec_1.js");
const JSONParser = require("../../formats/json/parser.js");
const StructuredHTTPReceiver = require("./receiver_structured.js");
const Spec = require("./spec_1.js");
const JSONParser = require("../../../formats/json/parser.js");
const jsonParserSpec = new JSONParser();
const parserByMime = {};
parserByMime[MIME_JSON] = jsonParserSpec;
parserByMime[MIME_CE_JSON] = jsonParserSpec;
const parserByMime = {
[MIME_JSON]: jsonParserSpec,
[MIME_CE_JSON]: jsonParserSpec
};
const allowedContentTypes = [];
allowedContentTypes.push(MIME_CE_JSON);
const allowedContentTypes = [ MIME_CE_JSON ];
function parser(name, parser = (v) => v) {
return { name: name, parser: parser};
@ -46,23 +44,14 @@ parserMap.set(SUBJECT, passThroughParser("subject"));
parserMap.set(DATA, passThroughParser("data"));
parserMap.set(DATA_BASE64, passThroughParser("data"));
// Leaving this in place for now. TODO: fixme
// eslint-disable-next-line
function Receiver(configuration) {
this.receiver = new StructuredHTTPReceiver(
parserByMime,
parserMap,
allowedContentTypes,
Spec
);
class Receiver {
constructor() {
this.parserByMime = parserByMime;
this.parserMap = parserMap;
this.allowedContentTypes = allowedContentTypes;
this.Spec = Spec;
this.spec = new Spec();
}
}
Receiver.prototype.check = function(payload, headers) {
this.receiver.check(payload, headers);
};
Receiver.prototype.parse = function(payload, headers) {
return this.receiver.parse(payload, headers);
};
module.exports = Receiver;

View File

@ -1,6 +1,6 @@
const { v4: uuidv4 } = require("uuid");
const Ajv = require("ajv");
const ValidationError = require("../validation_error.js");
const ValidationError = require("../validation/validation_error.js");
const {
asData,
@ -10,7 +10,7 @@ const {
isDate,
isBinary,
clone
} = require("../utils/fun.js");
} = require("../validation/fun.js");
const isValidType = (v) =>
(isBoolean(v) || isInteger(v) || isString(v) || isDate(v) || isBinary(v));
@ -122,7 +122,7 @@ function Spec1(_caller) {
};
if (!_caller) {
_caller = require("../cloudevent.js");
_caller = require("../../../cloudevent.js");
}
/*

View File

@ -0,0 +1,111 @@
const CloudEvent = require("../../../cloudevent.js");
const {
sanityAndClone,
validateArgs
} = require("./commons.js");
const ValidationError = require("./validation_error.js");
const {
HEADER_CONTENT_TYPE,
MIME_JSON,
DEFAULT_SPEC_VERSION_HEADER
} = require("../constants.js");
const {
isString,
isObject,
isBase64
} = require("./fun.js");
function check(payload, headers, receiver) {
// Validation Level 0
validateArgs(payload, headers);
// The receiver determines the specification version
if (!isObject(receiver)) throw new SyntaxError("no receiver");
// Clone and low case all headers names
const sanityHeaders = sanityAndClone(headers);
// Validation Level 1 - if content-type exists, be sure it's
// an allowed type
const contentTypeHeader = sanityHeaders[HEADER_CONTENT_TYPE];
const noContentType = !receiver.allowedContentTypes.includes(contentTypeHeader);
if (contentTypeHeader && noContentType) {
throw new ValidationError("invalid content type", [sanityHeaders[HEADER_CONTENT_TYPE]]);
}
receiver.requiredHeaders
.filter((required) => !sanityHeaders[required])
.forEach((required) => {
throw new ValidationError(`header '${required}' not found`);
});
if (sanityHeaders[DEFAULT_SPEC_VERSION_HEADER] !== receiver.specversion) {
throw new ValidationError("invalid spec version", [sanityHeaders[DEFAULT_SPEC_VERSION_HEADER]]);
}
}
function parse(payload, headers, receiver) {
payload = isString(payload) && isBase64(payload)
? Buffer.from(payload, "base64").toString()
: payload;
check(payload, headers, receiver);
// Clone and low case all headers names
const sanityHeaders = sanityAndClone(headers);
if (!sanityHeaders[HEADER_CONTENT_TYPE]) {
sanityHeaders[HEADER_CONTENT_TYPE] = MIME_JSON;
}
const processedHeaders = [];
const cloudevent = new CloudEvent(receiver.Spec);
const setterByHeader = receiver.setterByHeader;
// dont worry, check() have seen what was required or not
Array.from(Object.keys(setterByHeader))
.filter((header) => sanityHeaders[header])
.forEach((header) => {
const setterName = setterByHeader[header].name;
const parserFun = setterByHeader[header].parser;
// invoke the setter function
cloudevent[setterName](parserFun(sanityHeaders[header]));
// to use ahead, for extensions processing
processedHeaders.push(header);
});
// Parses the payload
const parsedPayload =
parserFor(receiver.parsersByEncoding, cloudevent, sanityHeaders)
.parse(payload);
// Every unprocessed header can be an extension
Array.from(Object.keys(sanityHeaders))
.filter((value) => !processedHeaders.includes(value))
.filter((value) => value.startsWith(receiver.extensionsPrefix))
.map((extension) => extension.substring(receiver.extensionsPrefix.length)
).forEach((extension) => cloudevent.addExtension(extension,
sanityHeaders[receiver.extensionsPrefix + extension])
);
// Sets the data
cloudevent.data(parsedPayload);
// Checks the event spec
cloudevent.format();
// return the result
return cloudevent;
}
function parserFor(parsersByEncoding, cloudevent, headers) {
const encoding = cloudevent.spec.payload.datacontentencoding;
return parsersByEncoding[encoding][headers[HEADER_CONTENT_TYPE]];
}
module.exports = {
check, parse
};

View File

@ -1,4 +1,10 @@
const Constants = require("./constants.js");
const ValidationError = require("./validation_error.js");
const Constants = require("../constants.js");
const {
isDefinedOrThrow,
isStringOrObjectOrThrow
} = require("./fun.js");
// Specific sanity for content-type header
function sanityContentType(contentType) {
@ -27,7 +33,19 @@ function sanityAndClone(headers) {
return sanityHeaders;
}
function validateArgs(payload, attributes) {
Array.of(payload)
.filter((p) => isDefinedOrThrow(p, new ValidationError("payload is null or undefined")))
.filter((p) => isStringOrObjectOrThrow(p, new ValidationError("payload must be an object or a string")))
.shift();
Array.of(attributes)
.filter((a) => isDefinedOrThrow(a, new ValidationError("attributes is null or undefined")))
.shift();
}
module.exports = {
sanityAndClone,
sanityContentType
sanityContentType,
validateArgs
};

View File

@ -0,0 +1,57 @@
const CloudEvent = require("../../../cloudevent.js");
const ValidationError = require("./validation_error.js");
const {
sanityAndClone,
validateArgs
} = require("./commons.js");
const {
HEADER_CONTENT_TYPE
} = require("../constants.js");
function check(payload, headers, receiver) {
validateArgs(payload, headers);
const sanityHeaders = sanityAndClone(headers);
// Validation Level 1
if (!receiver.allowedContentTypes
.includes(sanityHeaders[HEADER_CONTENT_TYPE])) {
throw new ValidationError("invalid content type", [sanityHeaders[HEADER_CONTENT_TYPE]]);
}
}
function parse(payload, headers, receiver) {
check(payload, headers, receiver);
const sanityHeaders = sanityAndClone(headers);
const contentType = sanityHeaders[HEADER_CONTENT_TYPE];
const parser = receiver.parserByMime[contentType];
const event = parser.parse(payload);
receiver.spec.check(event);
const processedAttributes = [];
const cloudevent = new CloudEvent(receiver.Spec);
receiver.parserMap.forEach((value, key) => {
if (event[key]) {
// invoke the setter function
cloudevent[value.name](value.parser(event[key]));
// to use ahead, for extensions processing
processedAttributes.push(key);
}
});
// Every unprocessed attribute should be an extension
Array.from(Object.keys(event))
.filter((attribute) => !processedAttributes.includes(attribute))
.forEach((extension) =>
cloudevent.addExtension(extension, event[extension])
);
return cloudevent;
}
module.exports = { parse, check };

View File

@ -7,7 +7,7 @@ class ValidationError extends TypeError {
* Constructs a new {ValidationError} with the message
* and array of additional errors.
* @param {string} message the error message
* @param {[string]|[ErrorObject]} [errors] any additional errors related to validation
* @param {string[]|ErrorObject[]} [errors] any additional errors related to validation
*/
constructor(message, errors) {
super(message);

View File

@ -1,4 +1,4 @@
const Spec = require("./specs/spec_1.js");
const Spec = require("./bindings/http/v1/spec_1.js");
const Formatter = require("./formats/json/formatter.js");
/**

View File

@ -2,8 +2,8 @@ const {
isString,
isDefinedOrThrow,
isStringOrObjectOrThrow
} = require("../../utils/fun.js");
const ValidationError = require("../../validation_error.js");
} = require("../../bindings/http/validation/fun.js");
const ValidationError = require("../../bindings/http/validation/validation_error.js");
const invalidPayloadTypeError = new ValidationError("invalid payload type, allowed are: string or object");
const nullOrUndefinedPayload = new ValidationError("null or undefined payload");

View File

@ -15,9 +15,7 @@
"release": "standard-version"
},
"files": [
"lib",
"v03",
"v1"
"lib"
],
"standard-version": {
"types": [

View File

@ -11,8 +11,8 @@ const {
const { CloudEvent, HTTPEmitter } = require("../../../");
const V1Spec = require("../../../v1").Spec;
const V03Spec = require("../../../v03").Spec;
const V1Spec = require("../../../lib/bindings/http/v1").Spec;
const V03Spec = require("../../../lib/bindings/http/v03").Spec;
const receiver = "https://cloudevents.io/";
const type = "com.example.test";

View File

@ -8,7 +8,7 @@ const {
BINARY_HEADERS_03,
BINARY_HEADERS_1
} = require("../../../lib/bindings/http/constants.js");
const ValidationError = require("../../../lib/validation_error.js");
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
const receiver = new HTTPReceiver();
const id = "1234";

View File

@ -1,14 +1,14 @@
const expect = require("chai").expect;
const HTTPBinaryReceiver = require("../../../lib/bindings/http/receiver_binary_0_3.js");
const ValidationError = require("../../../lib/validation_error.js");
const BinaryHTTPReceiver = require("../../../lib/bindings/http/receiver_binary.js");
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
const {
BINARY_HEADERS_03,
SPEC_V03,
HEADER_CONTENT_TYPE
} = require("../../../lib/bindings/http/constants.js");
const receiver = new HTTPBinaryReceiver();
const receiver = new BinaryHTTPReceiver(SPEC_V03);
describe("HTTP Transport Binding Binary Receiver for CloudEvents v0.3", () => {
describe("Check", () => {

View File

@ -1,16 +1,15 @@
const expect = require("chai").expect;
const { asBase64 } = require("../../../lib/utils/fun.js");
const { asBase64 } = require("../../../lib/bindings/http/validation/fun.js");
const {
BINARY_HEADERS_1,
SPEC_V1,
HEADER_CONTENT_TYPE
} = require("../../../lib/bindings/http/constants.js");
const ValidationError = require("../../../lib/validation_error.js");
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
const HTTPBinaryReceiver =
require("../../../lib/bindings/http/receiver_binary_1.js");
const BinaryHTTPReceiver = require("../../../lib/bindings/http/receiver_binary.js");
const receiver = new HTTPBinaryReceiver();
const receiver = new BinaryHTTPReceiver(SPEC_V1);
describe("HTTP Transport Binding Binary Receiver for CloudEvents v1.0", () => {
describe("Check", () => {

View File

@ -1,10 +1,11 @@
const expect = require("chai").expect;
const ValidationError = require("../../../lib/validation_error.js");
const HTTPStructuredReceiver = require("../../../lib/bindings/http/receiver_structured_0_3.js");
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
const HTTPStructuredReceiver = require("../../../lib/bindings/http/receiver_structured.js");
const CloudEvent = require("../../../lib/cloudevent.js");
const { Spec } = require("../../../v03/index.js");
const { Spec } = require("../../../lib/bindings/http/v03/index.js");
const { SPEC_V03 } = require("../../../lib/bindings/http/constants.js");
const receiver = new HTTPStructuredReceiver();
const receiver = new HTTPStructuredReceiver(SPEC_V03);
const type = "com.github.pull.create";
const source = "urn:event:from:myapi/resourse/123";
@ -51,7 +52,7 @@ describe("HTTP Transport Binding Structured Receiver CloudEvents v0.3", () => {
// act and assert
expect(receiver.check.bind(receiver, payload, attributes))
.to.throw(ValidationError, "payload must be an object or string");
.to.throw(ValidationError, "payload must be an object or a string");
});
it("Throw error when the content-type is invalid", () => {

View File

@ -1,11 +1,12 @@
const expect = require("chai").expect;
const { Spec } = require("../../../v1/index.js");
const { Spec } = require("../../../lib/bindings/http/v1/index.js");
const { CloudEvent } = require("../../../index.js");
const { asBase64 } = require("../../../lib/utils/fun.js");
const ValidationError = require("../../../lib/validation_error.js");
const HTTPStructuredReceiver = require("../../../lib/bindings/http/receiver_structured_1.js");
const { asBase64 } = require("../../../lib/bindings/http/validation/fun.js");
const { SPEC_V1 } = require("../../../lib/bindings/http/constants.js");
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
const HTTPStructuredReceiver = require("../../../lib/bindings/http/receiver_structured.js");
const receiver = new HTTPStructuredReceiver();
const receiver = new HTTPStructuredReceiver(SPEC_V1);
const type = "com.github.pull.create";
const source = "urn:event:from:myapi/resource/123";
@ -48,7 +49,7 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0",
// act and assert
expect(receiver.check.bind(receiver, payload, attributes))
.to.throw(ValidationError, "payload must be an object or string");
.to.throw(ValidationError, "payload must be an object or a string");
});
it("Throw error when the content-type is invalid", () => {

View File

@ -1,215 +0,0 @@
const expect = require("chai").expect;
const ValidationError = require("../../../lib/validation_error.js");
const Unmarshaller = require("../../../lib/bindings/http/unmarshaller_0_3.js");
const { CloudEvent } = require("../../../index.js");
const v03 = require("../../../v03/index.js");
const type = "com.github.pull.create";
const source = "urn:event:from:myapi/resourse/123";
const now = new Date();
const schemaurl = "http://cloudevents.io/schema.json";
const subject = "subject.ext";
const {
BINARY_HEADERS_03,
HEADER_CONTENT_TYPE,
BINARY
} = require("../../../lib/bindings/http/constants.js");
const ceContentType = "application/json";
const data = {
foo: "bar"
};
const un = new Unmarshaller();
describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => {
it("Throw error when payload is null", () => {
expect(() => un.unmarshall(null)).to.throw(ValidationError, "payload is null or undefined");
});
it("Throw error when headers is null", () => {
expect(() => un.unmarshall({})).to.throw(ValidationError, "headers is null or undefined");
expect(() => un.unmarshall({}, null)).to
.throw(ValidationError, "headers is null or undefined");
});
it("Throw error when there is no content-type header", () => {
expect(() => un.unmarshall({}, {})).to
.throw(ValidationError, "content-type header not found");
});
it("Throw error when content-type is not allowed", () => {
const headers = {
"content-type": "text/xml"
};
expect(() => un.unmarshall({}, headers)).to
.throw(ValidationError, "content type not allowed");
});
describe("Structured", () => {
it("Throw error when has not allowed mime", () => {
// setup
const headers = {
"content-type": "application/cloudevents+zip"
};
// act and assert
expect(() => un.unmarshall({}, headers)).to
.throw(ValidationError, "structured+type not allowed");
});
it("Throw error when the event does not follow the spec 0.3", () => {
const payload =
new CloudEvent(v03.Spec)
.time(now)
.toString();
const headers = {
"content-type": "application/cloudevents+json"
};
expect(() => un.unmarshall(payload, headers)).to.throw(ValidationError);
});
it("Should accept event TypeErrorthat follow the spec 0.3", () => {
const payload =
new CloudEvent(v03.Spec)
.type(type)
.data(data)
.source(source)
.dataContentType(ceContentType)
.time(now)
.schemaurl(schemaurl)
.subject(subject)
.format();
const headers = {
"content-type": "application/cloudevents+json"
};
const event = un.unmarshall(payload, headers);
expect(event instanceof CloudEvent).to.equal(true);
});
it("Should parse 'data' stringfied json to json object", () => {
// setup
const payload =
new CloudEvent(v03.Spec)
.type(type)
.source(source)
.dataContentType(ceContentType)
.time(now)
.schemaurl(schemaurl)
.subject(subject)
.data(JSON.stringify(data))
.toString();
const headers = {
"content-type": "application/cloudevents+json"
};
const event = un.unmarshall(payload, headers);
expect(event.getData()).to.deep.equal(data);
});
});
describe("Binary", () => {
it("Throw error when has not allowed mime", () => {
// setup
const payload = {
data: "dataString"
};
const attributes = {
[BINARY_HEADERS_03.TYPE]: "type",
[BINARY_HEADERS_03.SPEC_VERSION]: "0.3",
[BINARY_HEADERS_03.SOURCE]: "source",
[BINARY_HEADERS_03.ID]: "id",
[BINARY_HEADERS_03.TIME]: "2019-06-16T11:42:00Z",
[BINARY_HEADERS_03.SCHEMA_URL]: "http://schema.registry/v1",
[HEADER_CONTENT_TYPE]: "text/html"
};
expect(() => un.unmarshall(payload, attributes)).to
.throw(ValidationError, "content type not allowed");
});
it("Throw error when the event does not follow the spec 0.3", () => {
// setup
const payload = {
data: "dataString"
};
const attributes = {
[BINARY_HEADERS_03.TYPE]: "type",
"CE-CloudEventsVersion": "0.1",
[BINARY_HEADERS_03.SOURCE]: "source",
[BINARY_HEADERS_03.ID]: "id",
[BINARY_HEADERS_03.TIME]: "2019-06-16T11:42:00Z",
[BINARY_HEADERS_03.SCHEMA_URL]: "http://schema.registry/v1",
[HEADER_CONTENT_TYPE]: "application/json"
};
expect(() => un.unmarshall(payload, attributes)).to
.throw(ValidationError, "header 'ce-specversion' not found");
});
it("No error when all attributes are in place", () => {
// setup
const payload = {
data: "dataString"
};
const attributes = {
[BINARY_HEADERS_03.TYPE]: "type",
[BINARY_HEADERS_03.SPEC_VERSION]: "0.3",
[BINARY_HEADERS_03.SOURCE]: "source",
[BINARY_HEADERS_03.ID]: "id",
[BINARY_HEADERS_03.TIME]: "2019-06-16T11:42:00Z",
[BINARY_HEADERS_03.SCHEMA_URL]: "http://schema.registry/v1",
[HEADER_CONTENT_TYPE]: "application/json"
};
const event = un.unmarshall(payload, attributes);
expect(event instanceof CloudEvent).to.equal(true);
});
it("Throw error when 'ce-datacontentencoding' is not allowed", () => {
// setup
const payload = "eyJtdWNoIjoid293In0=";
const attributes = {
[BINARY_HEADERS_03.TYPE]: "type",
[BINARY_HEADERS_03.SPEC_VERSION]: "0.3",
[BINARY_HEADERS_03.SOURCE]: "source",
[BINARY_HEADERS_03.ID]: "id",
[BINARY_HEADERS_03.TIME]: "2019-06-16T11:42:00Z",
[BINARY_HEADERS_03.SCHEMA_URL]: "http://schema.registry/v1",
[HEADER_CONTENT_TYPE]: "application/json",
[BINARY_HEADERS_03.CONTENT_ENCODING]: BINARY
};
expect(() => un.unmarshall(payload, attributes)).to
.throw(ValidationError, "unsupported datacontentencoding");
});
it("No error when 'ce-datacontentencoding' is base64", () => {
// setup
const payload = "eyJtdWNoIjoid293In0=";
const expected = {
much: "wow"
};
const attributes = {
[BINARY_HEADERS_03.TYPE]: "type",
[BINARY_HEADERS_03.SPEC_VERSION]: "0.3",
[BINARY_HEADERS_03.SOURCE]: "source",
[BINARY_HEADERS_03.ID]: "id",
[BINARY_HEADERS_03.TIME]: "2019-06-16T11:42:00Z",
[BINARY_HEADERS_03.SCHEMA_URL]: "http://schema.registry/v1",
[HEADER_CONTENT_TYPE]: "application/json",
[BINARY_HEADERS_03.CONTENT_ENCODING]: "base64"
};
const event = un.unmarshall(payload, attributes);
expect(event.getData()).to.deep.equal(expected);
});
});
});

View File

@ -1,6 +1,6 @@
const expect = require("chai").expect;
const Parser = require("../../../lib/formats/json/parser.js");
const ValidationError = require("../../../lib/validation_error.js");
const ValidationError = require("../../../lib/bindings/http/validation/validation_error.js");
describe("JSON Event Format Parser", () => {
it("Throw error when payload is an integer", () => {

View File

@ -1,5 +1,5 @@
const expect = require("chai").expect;
const fun = require("../lib/utils/fun.js");
const fun = require("../lib/bindings/http/validation/fun.js");
describe("Functional approach", () => {
describe("isStringOrThrow", () => {

View File

@ -3,7 +3,7 @@ const nock = require("nock");
const BinaryHTTPEmitter = require("../lib/bindings/http/emitter_binary.js");
const StructuredHTTPEmitter = require("../lib/bindings/http/emitter_structured.js");
const CloudEvent = require("../lib/cloudevent.js");
const v03 = require("../v03/index.js");
const v03 = require("../lib/bindings/http/v03/index.js");
const {
SPEC_V03
} = require("../lib/bindings/http/constants.js");

View File

@ -1,12 +1,12 @@
const expect = require("chai").expect;
const nock = require("nock");
const https = require("https");
const { asBase64 } = require("../lib/utils/fun.js");
const { asBase64 } = require("../lib/bindings/http/validation/fun.js");
const {
SPEC_V1
} = require("../lib/bindings/http/constants.js");
const { Spec } = require("../v1/index.js");
const { Spec } = require("../lib/bindings/http/v1/index.js");
const CloudEvent = require("../lib/cloudevent.js");
const BinaryHTTPEmitter = require("../lib/bindings/http/emitter_binary.js");
const StructuredHTTPEmitter = require("../lib/bindings/http/emitter_structured.js");

View File

@ -1,7 +1,7 @@
const expect = require("chai").expect;
const { CloudEvent, HTTPReceiver, HTTPEmitter } = require("../");
const SpecV03 = require("../v03").Spec;
const SpecV1 = require("../v1").Spec;
const SpecV03 = require("../lib/bindings/http/v03").Spec;
const SpecV1 = require("../lib/bindings/http/v1").Spec;
const {
SPEC_V03,
SPEC_V1

View File

@ -1,5 +1,5 @@
const expect = require("chai").expect;
const Spec03 = require("../lib/specs/spec_0_3.js");
const Spec03 = require("../lib/bindings/http/v03/spec_0_3.js");
const { CloudEvent } = require("../index.js");
const {
MIME_JSON,
@ -7,7 +7,7 @@ const {
SPEC_V03,
BINARY
} = require("../lib/bindings/http/constants.js");
const ValidationError = require("../lib/validation_error.js");
const ValidationError = require("../lib/bindings/http/validation/validation_error.js");
const id = "97699ec2-a8d9-47c1-bfa0-ff7aa526f838";
const type = "com.github.pull.create";

View File

@ -1,9 +1,9 @@
const expect = require("chai").expect;
const Spec1 = require("../lib/specs/spec_1.js");
const Spec1 = require("../lib/bindings/http/v1/spec_1.js");
const { CloudEvent } = require("../index.js");
const { v4: uuidv4 } = require("uuid");
const { asBase64 } = require("../lib/utils/fun.js");
const ValidationError = require("../lib/validation_error.js");
const { asBase64 } = require("../lib/bindings/http/validation/fun.js");
const ValidationError = require("../lib/bindings/http/validation/validation_error.js");
const id = uuidv4();
const type = "com.github.pull.create";

View File

@ -1,5 +0,0 @@
const Spec = require("../lib/specs/spec_0_3.js");
module.exports = {
Spec
};

View File

@ -1,5 +0,0 @@
const Spec = require("../lib/specs/spec_1.js");
module.exports = {
Spec
};