Skip to content

Commit 5646005

Browse files
authored
Merge pull request #23 from Breeding-Insight/master
Adding credentials configuration option
2 parents 5802afa + b950db3 commit 5646005

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

docs/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ BrAPI.js supports BrAPI versions `v1.0`-`v2.0`. Currently, it expects a server t
2020
```bash
2121
# Be sure your version of NPM supports 'prepare' scripts (>=npm@4.0.0)
2222
# Recommended:
23-
npm install @solgenomics/brapijs
23+
npm install git+https://github.com/solgenomics/BrAPI-js
2424
# Otherwise:
25-
npm install git+https://github.com/solgenomics/BrAPI.js.git
26-
# or:
27-
git clone https://github.com/solgenomics/BrAPI.js.git
25+
git clone https://github.com/solgenomics/BrAPI-js.git
2826
cd BrAPI.js
2927
npm install .
3028
```
@@ -52,10 +50,11 @@ BrAPI.js has been designed to allow for many simultaneous and interdependent cal
5250

5351
### Initialization and Configuration
5452

55-
<a name="root" href="#root">#</a> **BrAPI**(_address_, [_version_, _auth_token_, _call_limit_]) [<>](main.js "Source")
53+
<a name="root" href="#root">#</a> **BrAPI**(_address_, [_version_, _auth_token_, _call_limit_, _credentials_]) [<>](main.js "Source")
5654

5755
Creates a root _BrAPINode_. This is the root of a BrAPI.js [DAG dataflow](#how-it-works). The _address_ should be a string with the base URL of a BrAPI instance that is being queried, i.e. "https://www.yambase.org/brapi/v1". If an _auth_token_ is provided, it will be added as a Bearer header when sending requests over HTTPS. Changing the _version_ determines which deprecation/removal warnings are written the console, it does not restrict functionality.
5856
The _call_limit_ parameter specifies how many simultaneous requests may be run by this node and its descendants against the specified server.
57+
The _credentials_ parameter allows you to define how HTTP credentials (aka cookies) should be included in a request. See https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials for more information.
5958

6059
###### Examples:
6160

@@ -89,7 +88,7 @@ var brapi_root1 = BrAPI("https://www.myserver.org/brapi/v1","v1.2") // for your
8988
.each(...);
9089
```
9190

92-
<a name="server" href="#server">#</a> _node_.**server**(_address_, [_version_, _auth_token_, _call_limit_]) [<>](src/BrAPINodes.js "Source")
91+
<a name="server" href="#server">#</a> _node_.**server**(_address_, [_version_, _auth_token_, _call_limit_, _credentials_]) [<>](src/BrAPINodes.js "Source")
9392

9493
Creates and returns a child _BrAPINode_ which changes the BrAPI server instance queried by all descendants.
9594

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@solgenomics/brapijs",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "BrAPI.js is a JavaScript client library for [BrAPI](https://brapi.org). It can be used either in the browser or within Node.js. It uses the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) (or [node-fetch]() in Node.js) for AJAX calls. BrAPI.js also uses ES6 classes.",
55
"bugs": {
66
"url": "https://github.com/solgenomics/BrAPI.js/issues"

src/BrAPINode.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,14 @@ class EmptyBrAPINode extends BrAPINode{
209209
EmptyBrAPINode.prototype.data = EmptyThreadNode.prototype.data;
210210

211211
class BrAPICallController {
212-
constructor(brapi_base_url,version,brapi_auth_token,max_calls){
212+
constructor(brapi_base_url,version,brapi_auth_token,max_calls,credentials){
213213
this.max_calls = max_calls || 5;
214214
this.call_queue = [];
215215
this.version = brapiVersion(version||1.2);
216216
this.running = 0;
217217
this.brapi_base_url = brapi_base_url;
218218
this.brapi_auth_token = brapi_auth_token;
219+
this.credentials = credentials || 'same-origin';
219220
}
220221
call(){
221222
var self = this;
@@ -250,7 +251,7 @@ class BrAPICallController {
250251
var fetch_opts = {
251252
method: method,
252253
cache: "no-cache",
253-
credentials: "same-origin",
254+
credentials: this.credentials,
254255
headers: {
255256
'Content-Type': 'application/json;charset=utf-8'
256257
},
@@ -397,11 +398,12 @@ Object.keys(brapiMethods).forEach(function(method_name){
397398
* @param {String} version Optional. BrAPI version of endpoint (e.g. "1.2" or "v1.1")
398399
* @param {String} auth_token Optional. BrAPI Auth Bearer token.
399400
* @param {Int} call_limit Optional. Maximum number of simultanious calls the server which can be running.
401+
* @param {String} credentials Optional. credentials option to use for fetch API. See: https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
400402
* @returns {EmptyBrAPINode}
401403
*/
402-
export function BrAPI(address, version, auth_token, call_limit){
404+
export function BrAPI(address, version, auth_token, call_limit, credentials){
403405
return new EmptyBrAPINode(
404-
new BrAPICallController(address,version,auth_token,call_limit||5)
406+
new BrAPICallController(address,version,auth_token,call_limit||5, credentials)
405407
);
406408
}
407409

0 commit comments

Comments
 (0)