@google-cloud/connect-datastore
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -13,2 +13,9 @@ ##### 1.0.0 - 09 January 2017 | ||
- Updated licensing, authors, contributors, readme | ||
## [3.1.0](https://www.github.com/googleapis/nodejs-datastore-session/compare/v3.0.1...v3.1.0) (2019-10-03) | ||
### Features | ||
* add option expirationMs ([#134](https://www.github.com/googleapis/nodejs-datastore-session/issues/134)) ([13d6e2c](https://www.github.com/googleapis/nodejs-datastore-session/commit/13d6e2c)) | ||
### [3.0.1](https://www.github.com/googleapis/nodejs-datastore-session/compare/v3.0.0...v3.0.1) (2019-06-26) | ||
@@ -15,0 +22,0 @@ |
{ | ||
"name": "@google-cloud/connect-datastore", | ||
"description": "Google Cloud Datastore session store for Express/Connect", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"license": "Apache-2.0", | ||
@@ -28,3 +28,3 @@ "author": "Google Inc.", | ||
"fix": "eslint --fix '**/*.js'", | ||
"docs-test": "linkinator docs -r --skip www.googleapis.com", | ||
"docs-test": "linkinator docs", | ||
"predocs-test": "npm run docs" | ||
@@ -34,5 +34,5 @@ }, | ||
"@google-cloud/datastore": "^4.0.0", | ||
"eslint": "^5.7.0", | ||
"eslint-config-prettier": "^4.0.0", | ||
"eslint-plugin-node": "^9.0.0", | ||
"eslint": "^6.0.0", | ||
"eslint-config-prettier": "^6.0.0", | ||
"eslint-plugin-node": "^10.0.0", | ||
"eslint-plugin-prettier": "^3.0.0", | ||
@@ -42,4 +42,4 @@ "express": "^4.16.4", | ||
"jsdoc": "^3.5.5", | ||
"jsdoc-baseline": "^0.1.0", | ||
"linkinator": "^1.1.2", | ||
"jsdoc-fresh": "^1.0.1", | ||
"linkinator": "^1.5.0", | ||
"mocha": "^6.0.0", | ||
@@ -46,0 +46,0 @@ "nyc": "^14.0.0", |
@@ -40,4 +40,11 @@ <img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Inc. logo" title="Google" align="right" height="96" width="96"/> | ||
store: new DatastoreStore({ | ||
kind: 'express-sessions', | ||
// Optional: expire the session after this many milliseconds. | ||
// note: datastore does not automatically delete all expired sessions | ||
// you may want to run separate cleanup requests to remove expired sessions | ||
// 0 means do not expire | ||
expirationMs: 0, | ||
dataset: new Datastore({ | ||
kind: 'express-sessions', | ||
@@ -59,2 +66,11 @@ // For convenience, @google-cloud/datastore automatically looks for the | ||
## Expiration | ||
If a session is fetched with the delta between the createdAt time and current | ||
time greater than expirationMs, the session will not be returned and will | ||
instead be destroyed. | ||
Datastore does not support a `ttl`, and tokens are only deleted if a session | ||
is fetched. You will likely want to implement logic to occasionally delete | ||
expired sessions. | ||
## Contributing | ||
@@ -61,0 +77,0 @@ |
/** | ||
* Copyright 2017, Google, Inc. | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
* Copyright 2017 Google LLC. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
@@ -30,2 +31,16 @@ * Unless required by applicable law or agreed to in writing, software | ||
this.kind = options.kind || 'Session'; | ||
if (options.expirationMs) { | ||
if ( | ||
typeof options.expirationMs !== typeof 0 || | ||
options.expirationMs < 0 | ||
) { | ||
throw new Error( | ||
'invalid value for option expirationMs: must be an integer greater than 0' | ||
); | ||
} | ||
this.expirationMs = parseInt(options.expirationMs, 10); | ||
} else { | ||
this.expirationMs = 0; | ||
} | ||
} | ||
@@ -48,2 +63,21 @@ | ||
} | ||
if (!entity.createdAt || !this.expirationMs) { | ||
return callback(null, result); | ||
} | ||
const createdAtMs = entity.createdAt.valueOf(); | ||
const expiresAtMs = createdAtMs + this.expirationMs; | ||
const nowMs = new Date().valueOf(); | ||
if (expiresAtMs <= nowMs) { | ||
this.destroy(sid, err => { | ||
if (err) { | ||
return callback(err); | ||
} | ||
return callback(); | ||
}); | ||
return; | ||
} | ||
return callback(null, result); | ||
@@ -63,12 +97,19 @@ }); | ||
const createdAt = new Date(); | ||
const data = [ | ||
{ | ||
name: 'data', | ||
value: sessJson, | ||
excludeFromIndexes: true, | ||
}, | ||
{ | ||
name: 'createdAt', | ||
value: createdAt, | ||
}, | ||
]; | ||
this.ds.save( | ||
{ | ||
key: this.ds.key([this.kind, sid]), | ||
data: [ | ||
{ | ||
name: 'data', | ||
value: sessJson, | ||
excludeFromIndexes: true, | ||
}, | ||
], | ||
data, | ||
}, | ||
@@ -75,0 +116,0 @@ callback |
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
25219
107
86