@spinajs/session-provider-db 1.2.108 → 1.2.114
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config/session-db.d.ts +1 -0
- package/lib/config/session-db.js +15 -0
- package/lib/config/session-db.js.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +66 -0
- package/lib/index.js.map +1 -0
- package/lib/migrations/AclSessionDBSqlMigration_2022_06_28_01_01_01.d.ts +5 -0
- package/lib/migrations/AclSessionDBSqlMigration_2022_06_28_01_01_01.js +30 -0
- package/lib/migrations/AclSessionDBSqlMigration_2022_06_28_01_01_01.js.map +1 -0
- package/lib/models/Session.d.ts +9 -0
- package/lib/models/Session.js +30 -0
- package/lib/models/Session.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path_1 = require("path");
|
|
4
|
+
function dir(path) {
|
|
5
|
+
return (0, path_1.resolve)((0, path_1.normalize)((0, path_1.join)(__dirname, path)));
|
|
6
|
+
}
|
|
7
|
+
module.exports = {
|
|
8
|
+
system: {
|
|
9
|
+
dirs: {
|
|
10
|
+
migrations: [dir('./../migrations')],
|
|
11
|
+
models: [dir('./../models')],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=session-db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-db.js","sourceRoot":"","sources":["../../src/config/session-db.ts"],"names":[],"mappings":";;AAAA,+BAAgD;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,OAAO,IAAA,cAAO,EAAC,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,OAAO,GAAG;IACf,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,UAAU,EAAE,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;YACpC,MAAM,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;SAC7B;KACF;CACF,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UserSessionData } from '@spinajs/rbac';
|
|
2
|
+
import { SessionProvider, Session } from '@spinajs/rbac';
|
|
3
|
+
import { Configuration } from '@spinajs/configuration';
|
|
4
|
+
import { Log } from '@spinajs/log';
|
|
5
|
+
export declare class DbSessionStore extends SessionProvider {
|
|
6
|
+
protected Log: Log;
|
|
7
|
+
protected Configuration: Configuration;
|
|
8
|
+
resolveAsync(): Promise<void>;
|
|
9
|
+
restoreSession(sessionId: string): Promise<Session>;
|
|
10
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
11
|
+
updateSession(s: UserSessionData): Promise<void>;
|
|
12
|
+
refreshSession(session: string | UserSessionData): Promise<void>;
|
|
13
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DbSessionStore = void 0;
|
|
13
|
+
const rbac_1 = require("@spinajs/rbac");
|
|
14
|
+
const di_1 = require("@spinajs/di");
|
|
15
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
16
|
+
const log_1 = require("@spinajs/log");
|
|
17
|
+
const Session_1 = require("./models/Session");
|
|
18
|
+
const orm_1 = require("@spinajs/orm");
|
|
19
|
+
const luxon_1 = require("luxon");
|
|
20
|
+
class DbSessionStore extends rbac_1.SessionProvider {
|
|
21
|
+
// tslint:disable-next-line: no-empty
|
|
22
|
+
async resolveAsync() { }
|
|
23
|
+
async restoreSession(sessionId) {
|
|
24
|
+
const session = await Session_1.DbSession.where({
|
|
25
|
+
SessionId: sessionId,
|
|
26
|
+
}).first();
|
|
27
|
+
if (!session) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (session.Expiration < luxon_1.DateTime.now()) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return new rbac_1.Session(Object.assign(Object.assign({}, session), { Creation: session.CreatedAt, Data: JSON.parse(session.Data) }));
|
|
34
|
+
}
|
|
35
|
+
async deleteSession(sessionId) {
|
|
36
|
+
const entry = await Session_1.DbSession.where('SessionId', sessionId).first();
|
|
37
|
+
if (entry) {
|
|
38
|
+
await entry.destroy();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async updateSession(s) {
|
|
42
|
+
const session = new Session_1.DbSession(Object.assign(Object.assign({}, s), { Data: JSON.stringify(s.Data) }));
|
|
43
|
+
await session.insert(orm_1.InsertBehaviour.InsertOrUpdate);
|
|
44
|
+
}
|
|
45
|
+
async refreshSession(session) {
|
|
46
|
+
let sInstance = null;
|
|
47
|
+
if (typeof session === 'string') {
|
|
48
|
+
sInstance = await this.restoreSession(session);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
sInstance = new rbac_1.Session(session);
|
|
52
|
+
}
|
|
53
|
+
sInstance.extend(this.Configuration.get('acl.session.expiration', 10));
|
|
54
|
+
await this.updateSession(sInstance);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, log_1.Logger)('db-session-store'),
|
|
59
|
+
__metadata("design:type", log_1.Log)
|
|
60
|
+
], DbSessionStore.prototype, "Log", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, di_1.Autoinject)(),
|
|
63
|
+
__metadata("design:type", configuration_1.Configuration)
|
|
64
|
+
], DbSessionStore.prototype, "Configuration", void 0);
|
|
65
|
+
exports.DbSessionStore = DbSessionStore;
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,wCAAyD;AACzD,oCAAyC;AACzC,0DAAuD;AACvD,sCAA2C;AAC3C,8CAA6C;AAC7C,sCAA+C;AAC/C,iCAAiC;AAEjC,MAAa,cAAe,SAAQ,sBAAe;IAOjD,qCAAqC;IAC9B,KAAK,CAAC,YAAY,KAAI,CAAC;IAEvB,KAAK,CAAC,cAAc,CAAC,SAAiB;QAC3C,MAAM,OAAO,GAAG,MAAM,mBAAS,CAAC,KAAK,CAAC;YACpC,SAAS,EAAE,SAAS;SACrB,CAAC,CAAC,KAAK,EAAE,CAAC;QAEX,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO,IAAI,CAAC;SACb;QAED,IAAI,OAAO,CAAC,UAAU,GAAG,gBAAQ,CAAC,GAAG,EAAE,EAAE;YACvC,OAAO,IAAI,CAAC;SACb;QAED,OAAO,IAAI,cAAO,iCACb,OAAO,KACV,QAAQ,EAAE,OAAO,CAAC,SAAS,EAC3B,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAC9B,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,SAAiB;QAC1C,MAAM,KAAK,GAAG,MAAM,mBAAS,CAAC,KAAK,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;QACpE,IAAI,KAAK,EAAE;YACT,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;SACvB;IACH,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,CAAkB;QAC3C,MAAM,OAAO,GAAG,IAAI,mBAAS,iCACxB,CAAC,KACJ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAC5B,CAAC;QAEH,MAAM,OAAO,CAAC,MAAM,CAAC,qBAAe,CAAC,cAAc,CAAC,CAAC;IACvD,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,OAAiC;QAC3D,IAAI,SAAS,GAAY,IAAI,CAAC;QAE9B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC/B,SAAS,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;SAChD;aAAM;YACL,SAAS,GAAG,IAAI,cAAO,CAAC,OAAO,CAAC,CAAC;SAClC;QAED,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,wBAAwB,EAAE,EAAE,CAAC,CAAC,CAAC;QAC/E,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;IACtC,CAAC;CACF;AAxDC;IADC,IAAA,YAAM,EAAC,kBAAkB,CAAC;8BACZ,SAAG;2CAAC;AAGnB;IADC,IAAA,eAAU,GAAE;8BACY,6BAAa;qDAAC;AALzC,wCA0DC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AclSessionDBSqlMigration_2022_06_28_01_01_01 = void 0;
|
|
10
|
+
const orm_1 = require("@spinajs/orm");
|
|
11
|
+
let AclSessionDBSqlMigration_2022_06_28_01_01_01 = class AclSessionDBSqlMigration_2022_06_28_01_01_01 extends orm_1.OrmMigration {
|
|
12
|
+
async up(connection) {
|
|
13
|
+
await connection.schema().createTable('acl_sessions', (table) => {
|
|
14
|
+
table.int('Id').primaryKey().autoIncrement();
|
|
15
|
+
table.string('SessionId', 255).notNull();
|
|
16
|
+
table.date('CreatedAt').notNull();
|
|
17
|
+
table.date('Expiration').notNull();
|
|
18
|
+
table.text('Data').notNull();
|
|
19
|
+
});
|
|
20
|
+
// create index explicit, otherwise sqlite driver cannot extract unique index from sqlite_master
|
|
21
|
+
await connection.index().table('acl_sessions').name('session_id_acl_session_idx').columns(['SessionId']).unique();
|
|
22
|
+
}
|
|
23
|
+
// tslint:disable-next-line: no-empty
|
|
24
|
+
async down(_) { }
|
|
25
|
+
};
|
|
26
|
+
AclSessionDBSqlMigration_2022_06_28_01_01_01 = __decorate([
|
|
27
|
+
(0, orm_1.Migration)('default')
|
|
28
|
+
], AclSessionDBSqlMigration_2022_06_28_01_01_01);
|
|
29
|
+
exports.AclSessionDBSqlMigration_2022_06_28_01_01_01 = AclSessionDBSqlMigration_2022_06_28_01_01_01;
|
|
30
|
+
//# sourceMappingURL=AclSessionDBSqlMigration_2022_06_28_01_01_01.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AclSessionDBSqlMigration_2022_06_28_01_01_01.js","sourceRoot":"","sources":["../../src/migrations/AclSessionDBSqlMigration_2022_06_28_01_01_01.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sCAAkE;AAGlE,IAAa,4CAA4C,GAAzD,MAAa,4CAA6C,SAAQ,kBAAY;IACrE,KAAK,CAAC,EAAE,CAAC,UAAqB;QACnC,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,EAAE;YAC9D,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE,CAAC;YAC7C,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;YACzC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC;YAClC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC;YACnC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,gGAAgG;QAChG,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IACpH,CAAC;IAED,qCAAqC;IAC9B,KAAK,CAAC,IAAI,CAAC,CAAY,IAAkB,CAAC;CAClD,CAAA;AAhBY,4CAA4C;IADxD,IAAA,eAAS,EAAC,SAAS,CAAC;GACR,4CAA4C,CAgBxD;AAhBY,oGAA4C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DbSession = void 0;
|
|
13
|
+
const orm_1 = require("@spinajs/orm");
|
|
14
|
+
const luxon_1 = require("luxon");
|
|
15
|
+
let DbSession = class DbSession extends orm_1.ModelBase {
|
|
16
|
+
};
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, orm_1.Primary)(),
|
|
19
|
+
__metadata("design:type", Number)
|
|
20
|
+
], DbSession.prototype, "Id", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, orm_1.CreatedAt)(),
|
|
23
|
+
__metadata("design:type", luxon_1.DateTime)
|
|
24
|
+
], DbSession.prototype, "CreatedAt", void 0);
|
|
25
|
+
DbSession = __decorate([
|
|
26
|
+
(0, orm_1.Connection)('default'),
|
|
27
|
+
(0, orm_1.Model)('acl_sessions')
|
|
28
|
+
], DbSession);
|
|
29
|
+
exports.DbSession = DbSession;
|
|
30
|
+
//# sourceMappingURL=Session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Session.js","sourceRoot":"","sources":["../../src/models/Session.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,sCAAgF;AAChF,iCAAiC;AAIjC,IAAa,SAAS,GAAtB,MAAa,SAAU,SAAQ,eAAS;CAYvC,CAAA;AAVC;IADC,IAAA,aAAO,GAAE;;qCACQ;AAKlB;IADC,IAAA,eAAS,GAAE;8BACM,gBAAQ;4CAAC;AAPhB,SAAS;IAFrB,IAAA,gBAAU,EAAC,SAAS,CAAC;IACrB,IAAA,WAAK,EAAC,cAAc,CAAC;GACT,SAAS,CAYrB;AAZY,8BAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spinajs/session-provider-db",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.114",
|
|
4
4
|
"description": "Simple session provider based on relational db. Usefull for testing or small projects",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"private": false,
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@spinajs/orm-sqlite": "^1.2.108"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "857b782b8d257e6d193b16251fd197db90d62678"
|
|
54
54
|
}
|