Skip to content

Commit

Permalink
Symbol documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs224 committed Apr 26, 2024
1 parent e0b8d4c commit f96de4e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Crypto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import { Iron } from '../deps.ts'

/**
* Encrypt a string or object value
*
* @param password Random string at least 32 characters long
* @param payload String or object to encrypt
* @returns A promise of the encrypted string
*/
export async function encrypt(password: string, payload: object | string): Promise<string> {
return await Iron.seal(globalThis.crypto, payload, password, Iron.defaults)
}

/**
* Decrypt an encrypted payload
*
* @param password Random string at least 32 characters long
* @param encrypted Encrypted string
* @returns Promise of the unencrypted value (string or object in most cases)
*/
export async function decrypt(password:string, encrypted: string): Promise<unknown> {
return await Iron.unseal(globalThis.crypto, encrypted, {default: password}, Iron.defaults)
}
1 change: 1 addition & 0 deletions src/Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface SessionOptions {
sessionCookieName?: string
}

/** Function that returns a Hono-compatible session middleware */
export function sessionMiddleware(options: SessionOptions): MiddlewareHandler<any, any, {}> {

const store = options.store
Expand Down
6 changes: 6 additions & 0 deletions src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ interface SessionDataEntry {
flash: boolean
}

/**
* Interface for specifying the necessary data for a session entry
*/
export interface SessionData {
_data: Record<string, SessionDataEntry>,
_expire: string | null,
_delete: boolean,
_accessed: string | null,
}

/**
* Session class with methods for interacting with the session
*/
export class Session {

private cache: SessionData
Expand Down
4 changes: 4 additions & 0 deletions src/store/CookieStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ interface CookieStoreOptions {
cookieOptions?: CookieOptions,
sessionCookieName: string
}

/**
* Cookie storage driver class
*/
class CookieStore {
public encryptionKey: string | null | undefined
public cookieOptions: CookieOptions | undefined
Expand Down
3 changes: 3 additions & 0 deletions src/store/MemoryStore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Store from './Store.ts'
import { SessionData } from '../../mod.ts'

/**
* Memory storage driver class
*/
class MemoryStore implements Store {
private data: Map<string, SessionData>

Expand Down
3 changes: 3 additions & 0 deletions src/store/Store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { SessionData } from "../../mod.ts"

/**
* Interface for required methods in session storage drivers
*/
export default interface Store {
getSessionById(sessionId?: string) : SessionData | null | undefined | Promise<SessionData | null | undefined>
createSession(sessionId: string, initialData: SessionData) : Promise<void> | void
Expand Down

0 comments on commit f96de4e

Please sign in to comment.