Comparing version 4.3.0 to 4.4.0
28
nano.js
@@ -369,2 +369,28 @@ /* minimal couch in node | ||
/*************************************************************************** | ||
* session * | ||
***************************************************************************/ | ||
/* | ||
* gets the current session if there us one | ||
* | ||
* e.g. | ||
* nano.session(function (err, session) { | ||
* if (err) { | ||
* return console.log('oh noes!') | ||
* } | ||
* | ||
* console.log('user is %s and has these roles: %j', | ||
* session.userCtx.user, session.userCtx.roles); | ||
* | ||
* }); | ||
* | ||
* @see relax | ||
*/ | ||
function session(callback) { | ||
return relax( | ||
{ method : 'GET' | ||
, db : '_session' | ||
}, callback); | ||
} | ||
/*************************************************************************** | ||
* db * | ||
@@ -1078,2 +1104,3 @@ ***************************************************************************/ | ||
, auth : auth_server // alias | ||
, session : session | ||
, insert : insert_doc | ||
@@ -1134,2 +1161,3 @@ , get : get_doc | ||
, auth : auth_server | ||
, session : session | ||
}; | ||
@@ -1136,0 +1164,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"repository": "git://github.com/dscape/nano", | ||
"version": "4.3.0", | ||
"version": "4.4.0", | ||
"author": "Nuno Job <nunojobpinto@gmail.com> (http://nunojob.com)", | ||
@@ -9,0 +9,0 @@ "contributors": [ |
@@ -8,6 +8,6 @@ # nano | ||
* **minimalistic** - there is only a minimum of abstraction between you and | ||
* **minimalistic** - there is only a minimum of abstraction between you and | ||
couchdb | ||
* **pipes** - proxy requests from couchdb directly to your end user | ||
* **errors** - errors are proxied directly from couchdb: if you know couchdb | ||
* **errors** - errors are proxied directly from couchdb: if you know couchdb | ||
you already know `nano`. | ||
@@ -85,3 +85,3 @@ | ||
in this examples we didn't specify a `callback` function, the absence of a | ||
in this examples we didn't specify a `callback` function, the absence of a | ||
callback means _"do this, ignore what happens"_. | ||
@@ -91,3 +91,3 @@ in `nano` the callback function receives always three arguments: | ||
* `err` - the error, if any | ||
* `body` - the http _response body_ from couchdb, if no error. | ||
* `body` - the http _response body_ from couchdb, if no error. | ||
json parsed body, binary for non json responses | ||
@@ -161,3 +161,3 @@ * `header` - the http _response header_ from couchdb, if no error | ||
, "request_defaults" : { "proxy" : "http://someproxy" } | ||
, "log" : function (id, args) { | ||
, "log" : function (id, args) { | ||
console.log(id, args); | ||
@@ -167,3 +167,3 @@ } | ||
``` | ||
Please check [request] for more information on the defaults. They support features like cookie jar, proxies, ssl, etc. | ||
Please check [request] for more information on the defaults. They support features like cookie jar, proxies, ssl, etc. | ||
@@ -260,3 +260,3 @@ ### pool size and open sockets | ||
{ create_target:true }, function(err, body) { | ||
if (!err) | ||
if (!err) | ||
console.log(body); | ||
@@ -419,3 +419,3 @@ }); | ||
bulk operations(update/delete/insert) on the database, refer to the | ||
bulk operations(update/delete/insert) on the database, refer to the | ||
[couchdb doc](http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API). | ||
@@ -425,3 +425,3 @@ | ||
list all the docs in the database with optional query string additions `params`. | ||
list all the docs in the database with optional query string additions `params`. | ||
@@ -440,6 +440,6 @@ ``` js | ||
bulk fetch of the database documents, `docnames` are specified as per | ||
bulk fetch of the database documents, `docnames` are specified as per | ||
[couchdb doc](http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API). | ||
additional query string `params` can be specified, `include_docs` is always set | ||
to `true`. | ||
to `true`. | ||
@@ -516,3 +516,3 @@ ## multipart functions | ||
get `docname`'s attachment `attname` with optional query string additions | ||
`params`. | ||
`params`. | ||
@@ -581,4 +581,4 @@ ``` js | ||
calls a show function of the specified design for the document specified by doc_id with | ||
optional query string additions `params`. | ||
calls a show function of the specified design for the document specified by doc_id with | ||
optional query string additions `params`. | ||
@@ -600,3 +600,3 @@ ``` js | ||
``` js | ||
db.atomic("update", "inplace", "foobar", | ||
db.atomic("update", "inplace", "foobar", | ||
{field: "foo", value: "bar"}, function (error, response) { | ||
@@ -610,3 +610,3 @@ assert.equal(error, undefined, "failed to update"); | ||
calls a view of the specified design with optional query string additions `params`. | ||
calls a view of the specified design with optional query string additions `params`. | ||
@@ -636,3 +636,3 @@ ``` js | ||
nano.auth(username, userpass, function (err, body, headers) { | ||
if (err) { | ||
if (err) { | ||
return callback(err); | ||
@@ -672,2 +672,18 @@ } | ||
getting current session: | ||
```javascript | ||
var nano = require('nano')({url: 'http://localhost:5984', cookie: 'AuthSession=' + auth}); | ||
nano.session(function(err, session) { | ||
if (err) { | ||
return console.log('oh noes!') | ||
} | ||
console.log('user is %s and has these roles: %j', | ||
session.userCtx.user, session.userCtx.roles); | ||
}); | ||
``` | ||
## advanced features | ||
@@ -700,3 +716,3 @@ | ||
you can pipe in nano like in any other stream. | ||
you can pipe in nano like in any other stream. | ||
for example if our `rabbit` document has an attachment with name `picture.png` | ||
@@ -703,0 +719,0 @@ (with a picture of our white rabbit, of course!) you can pipe it to a `writable |
@@ -27,6 +27,6 @@ var specify = require("specify") | ||
// authenticate | ||
nano.auth(helpers.username, helpers.password, | ||
nano.auth(helpers.username, helpers.password, | ||
function (err, response, headers) { | ||
assert.equal(err, undefined, "Should have logged in successfully"); | ||
assert.ok(headers['set-cookie'], | ||
assert.ok(headers['set-cookie'], | ||
"Response should have a set-cookie header"); | ||
@@ -50,2 +50,10 @@ cookie = headers['set-cookie']; | ||
specify("shared_cookie:get_session", timeout, function (assert) { | ||
var server = Nano({ url : helpers.couch, cookie: cookie }); | ||
server.session(function(error, session) { | ||
assert.equal(error, undefined, "Should have gotten the session"); | ||
assert.equal(session.userCtx.name, helpers.username); | ||
}); | ||
}); | ||
specify("shared_cookie:teardown", timeout, function (assert) { | ||
@@ -52,0 +60,0 @@ // back to admin party mode |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
178811
4162
787