hyper-ts-session
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.1.2](https://github.com/thewilkybarkid/hyper-ts-session/compare/v0.1.1...v0.1.2) (2022-05-25) | ||
### Features | ||
* end the current session ([afbcfcf](https://github.com/thewilkybarkid/hyper-ts-session/commit/afbcfcf0a787271ea0e6e9b0dd5ff179695935d2)) | ||
### [0.1.1](https://github.com/thewilkybarkid/hyper-ts-session/compare/v0.1.0...v0.1.1) (2022-05-24) | ||
@@ -7,0 +14,0 @@ |
@@ -29,1 +29,8 @@ import * as J from 'fp-ts/Json'; | ||
export declare function storeSession(session: JsonRecord): ReaderMiddleware<SessionEnv, HeadersOpen, HeadersOpen, never, void>; | ||
/** | ||
* Returns a middleware that ends the current session. | ||
* | ||
* @category constructors | ||
* @since 0.1.2 | ||
*/ | ||
export declare function endSession(): ReaderMiddleware<SessionEnv, HeadersOpen, HeadersOpen, never, void>; |
@@ -38,3 +38,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.storeSession = exports.getSession = void 0; | ||
exports.endSession = exports.storeSession = exports.getSession = void 0; | ||
/** | ||
@@ -77,2 +77,14 @@ * @since 0.1.0 | ||
exports.storeSession = storeSession; | ||
/** | ||
* Returns a middleware that ends the current session. | ||
* | ||
* @category constructors | ||
* @since 0.1.2 | ||
*/ | ||
function endSession() { | ||
return (0, function_1.pipe)(RM.clearCookie('session', { | ||
httpOnly: true, | ||
}), RM.chain(() => currentSessionId()), RM.chainReaderTaskK(deleteSession), RM.orElseW(() => RM.right(undefined))); | ||
} | ||
exports.endSession = endSession; | ||
// ------------------------------------------------------------------------------------- | ||
@@ -94,2 +106,7 @@ // utils | ||
} | ||
function deleteSession(key) { | ||
return (0, function_1.flow)(TE.tryCatchK(({ sessionStore }) => __awaiter(this, void 0, void 0, function* () { | ||
yield sessionStore.delete(key); | ||
}), function_1.constVoid), TE.toUnion); | ||
} | ||
function getCookie(name) { | ||
@@ -96,0 +113,0 @@ return (0, function_1.pipe)(getCookies(), M.chainEitherKW(E.fromOptionK(() => 'no-cookie')(r.lookup(name))), M.mapLeft(() => 'no-cookie')); |
{ | ||
"name": "hyper-ts-session", | ||
"description": "hyper-ts middleware for sessions.", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/thewilkybarkid/hyper-ts-session", |
11539
151