@prairielearn/session 3.0.5 → 3.0.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @prairielearn/session
2
2
 
3
+ ## 3.0.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 4b79275: Upgrade all JavaScript dependencies
8
+
9
+ ## 3.0.6
10
+
11
+ ### Patch Changes
12
+
13
+ - 4ab7483: Remove remnants of `express-session` package
14
+
3
15
  ## 3.0.5
4
16
 
5
17
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { SessionStore, SessionStoreData } from './store.js';
1
+ import { type SessionStore, type SessionStoreData } from './store.js';
2
2
  export declare class MemoryStore implements SessionStore {
3
3
  private sessions;
4
4
  set(id: string, session: any, expiresAt: Date): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"memory-store.js","sourceRoot":"","sources":["../src/memory-store.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAW;IACd,QAAQ,GAAG,IAAI,GAAG,EAA6C,CAAC;IAExE,KAAK,CAAC,GAAG,CAAC,EAAU,EAAE,OAAY,EAAE,SAAe;QACjD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE;YACpB,SAAS;YACT,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACxB,OAAO;YACL,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;SAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { SessionStore, SessionStoreData } from './store.js';\n\nexport class MemoryStore implements SessionStore {\n private sessions = new Map<string, { expiresAt: Date; data: string }>();\n\n async set(id: string, session: any, expiresAt: Date): Promise<void> {\n this.sessions.set(id, {\n expiresAt,\n data: JSON.stringify(session),\n });\n }\n\n async get(id: string): Promise<SessionStoreData | null> {\n const value = this.sessions.get(id);\n if (!value) return null;\n return {\n expiresAt: value.expiresAt,\n data: JSON.parse(value.data),\n };\n }\n\n async destroy(id: string): Promise<void> {\n this.sessions.delete(id);\n }\n}\n"]}
1
+ {"version":3,"file":"memory-store.js","sourceRoot":"","sources":["../src/memory-store.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,WAAW;IACd,QAAQ,GAAG,IAAI,GAAG,EAA6C,CAAC;IAExE,KAAK,CAAC,GAAG,CAAC,EAAU,EAAE,OAAY,EAAE,SAAe;QACjD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE;YACpB,SAAS;YACT,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QACxB,OAAO;YACL,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;SAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAU;QACtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;CACF","sourcesContent":["import { type SessionStore, type SessionStoreData } from './store.js';\n\nexport class MemoryStore implements SessionStore {\n private sessions = new Map<string, { expiresAt: Date; data: string }>();\n\n async set(id: string, session: any, expiresAt: Date): Promise<void> {\n this.sessions.set(id, {\n expiresAt,\n data: JSON.stringify(session),\n });\n }\n\n async get(id: string): Promise<SessionStoreData | null> {\n const value = this.sessions.get(id);\n if (!value) return null;\n return {\n expiresAt: value.expiresAt,\n data: JSON.parse(value.data),\n };\n }\n\n async destroy(id: string): Promise<void> {\n this.sessions.delete(id);\n }\n}\n"]}
package/dist/session.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Request } from 'express';
2
- import { SessionStore } from './store.js';
2
+ import { type SessionStore } from './store.js';
3
3
  export interface Session {
4
4
  id: string;
5
5
  destroy(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,OAAO,GAAG,MAAM,UAAU,CAAC;AAa3B,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,SAAiB,EACjB,GAAY,EACZ,KAAmB,EACnB,MAAc;IAEd,MAAM,gBAAgB,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,gBAAgB,EAAE,SAAS,IAAI,IAAI,CAAC;IAEtD,MAAM,OAAO,GAAG,WAAW,CAAC,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAEtE,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;QAC7B,wEAAwE;QACxE,6DAA6D;QAC7D,MAAM,KAAK,CAAC,GAAG,CACb,SAAS,EACT,OAAO;QACP,sEAAsE;QACtE,oEAAoE;QACpE,sBAAsB;QACtB,sBAAsB,CAAC,O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AAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,oBAAoB,CAA2B,OAAO,EAAE,eAAe,EAAE,CAAC,UAAU,EAAE,EAAE;QACtF,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;YACnC,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,CAAC;QAChD,CAAC;aAAM,CAAC;YACN,SAAS,GAAG,UAAU,CAAC;QACzB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAkB,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,oBAAoB,CAAI,GAAW,EAAE,IAAY,EAAE,EAAK;IAC/D,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE;QAC/B,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,EAAE;KACV,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAU;IAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC5B,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACrD,OAAO,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import crypto from 'node:crypto';\n\nimport type { Request } from 'express';\nimport uid from 'uid-safe';\n\nimport { SessionStore } from './store.js';\n\nexport interface Session {\n id: string;\n destroy(): Promise<void>;\n regenerate(): Promise<void>;\n setExpiration(expiry: Date | number): void;\n getExpirationDate(): Date;\n [key: string]: any;\n}\n\nexport async function generateSessionId(): Promise<string> {\n return await uid(24);\n}\n\nexport async function loadSession(\n sessionId: string,\n req: Request,\n store: SessionStore,\n maxAge: number,\n): Promise<Session> {\n const sessionStoreData = await store.get(sessionId);\n const expiresAt = sessionStoreData?.expiresAt ?? null;\n\n const session = makeSession(sessionId, req, store, expiresAt, maxAge);\n\n if (sessionStoreData == null) {\n // Immediately persis the new session to the store so that it's assigned\n // an ID and available to query later on in the same request.\n await store.set(\n sessionId,\n session,\n // Cookies only support second-level resolution. To ensure consistency\n // between the cookie and the store, truncate the expiration date to\n // the nearest second.\n truncateExpirationDate(session.getExpirationDate()),\n );\n }\n\n // Copy session data into the session object.\n if (sessionStoreData != null) {\n const { data } = sessionStoreData;\n for (const prop in data) {\n if (!(prop in session)) {\n session[prop] = data[prop];\n }\n }\n }\n\n return session;\n}\n\nexport function makeSession(\n sessionId: string,\n req: Request,\n store: SessionStore,\n expirationDate: Date | null,\n maxAge: number,\n): Session {\n const session = {};\n\n let expiresAt = expirationDate;\n\n defineStaticProperty<Session['id']>(session, 'id', sessionId);\n\n defineStaticProperty<Session['destroy']>(session, 'destroy', async () => {\n delete (req as any).session;\n await store.destroy(sessionId);\n });\n\n defineStaticProperty<Session['regenerate']>(session, 'regenerate', async () => {\n await store.destroy(sessionId);\n req.session = makeSession(await generateSessionId(), req, store, null, maxAge);\n });\n\n defineStaticProperty<Session['getExpirationDate']>(session, 'getExpirationDate', () => {\n if (expiresAt == null) {\n expiresAt = new Date(Date.now() + maxAge);\n }\n return expiresAt;\n });\n\n defineStaticProperty<Session['setExpiration']>(session, 'setExpiration', (expiration) => {\n if (typeof expiration === 'number') {\n expiresAt = new Date(Date.now() + expiration);\n } else {\n expiresAt = expiration;\n }\n });\n\n return session as Session;\n}\n\nexport function hashSession(session: Session): string {\n const str = JSON.stringify(session);\n return crypto.createHash('sha1').update(str, 'utf8').digest('hex');\n}\n\nfunction defineStaticProperty<T>(obj: object, name: string, fn: T) {\n Object.defineProperty(obj, name, {\n configurable: false,\n enumerable: false,\n writable: false,\n value: fn,\n });\n}\n\nexport function truncateExpirationDate(date: Date) {\n const time = date.getTime();\n const truncatedTime = Math.floor(time / 1000) * 1000;\n return new Date(truncatedTime);\n}\n"]}
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAGjC,OAAO,GAAG,MAAM,UAAU,CAAC;AAa3B,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,SAAiB,EACjB,GAAY,EACZ,KAAmB,EACnB,MAAc;IAEd,MAAM,gBAAgB,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,gBAAgB,EAAE,SAAS,IAAI,IAAI,CAAC;IAEtD,MAAM,OAAO,GAAG,WAAW,CAAC,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAEtE,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;QAC7B,wEAAwE;QACxE,6DAA6D;QAC7D,MAAM,KAAK,CAAC,GAAG,CACb,SAAS,EACT,OAAO;QACP,sEAAsE;QACtE,oEAAoE;QACpE,sBAAsB;QACtB,sBAAsB,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CACpD,CAAC;IACJ,CAAC;IAED,6CAA6C;IAC7C,IAAI,gBAAgB,IAAI,IAAI,EAAE,CAAC;QAC7B,MAAM,EAAE,IAAI,EAAE,GAAG,gBAAgB,CAAC;QAClC,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;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CAAC;YACnC,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,CAAC;QAChD,CAAC;aAAM,CAAC;YACN,SAAS,GAAG,UAAU,CAAC;QACzB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAkB,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAgB;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACpC,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrE,CAAC;AAED,SAAS,oBAAoB,CAAI,GAAW,EAAE,IAAY,EAAE,EAAK;IAC/D,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE;QAC/B,YAAY,EAAE,KAAK;QACnB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,KAAK;QACf,KAAK,EAAE,EAAE;KACV,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAU;IAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC5B,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IACrD,OAAO,IAAI,IAAI,CAAC,aAAa,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import crypto from 'node:crypto';\n\nimport type { Request } from 'express';\nimport uid from 'uid-safe';\n\nimport { type SessionStore } from './store.js';\n\nexport interface Session {\n id: string;\n destroy(): Promise<void>;\n regenerate(): Promise<void>;\n setExpiration(expiry: Date | number): void;\n getExpirationDate(): Date;\n [key: string]: any;\n}\n\nexport async function generateSessionId(): Promise<string> {\n return await uid(24);\n}\n\nexport async function loadSession(\n sessionId: string,\n req: Request,\n store: SessionStore,\n maxAge: number,\n): Promise<Session> {\n const sessionStoreData = await store.get(sessionId);\n const expiresAt = sessionStoreData?.expiresAt ?? null;\n\n const session = makeSession(sessionId, req, store, expiresAt, maxAge);\n\n if (sessionStoreData == null) {\n // Immediately persis the new session to the store so that it's assigned\n // an ID and available to query later on in the same request.\n await store.set(\n sessionId,\n session,\n // Cookies only support second-level resolution. To ensure consistency\n // between the cookie and the store, truncate the expiration date to\n // the nearest second.\n truncateExpirationDate(session.getExpirationDate()),\n );\n }\n\n // Copy session data into the session object.\n if (sessionStoreData != null) {\n const { data } = sessionStoreData;\n for (const prop in data) {\n if (!(prop in session)) {\n session[prop] = data[prop];\n }\n }\n }\n\n return session;\n}\n\nexport function makeSession(\n sessionId: string,\n req: Request,\n store: SessionStore,\n expirationDate: Date | null,\n maxAge: number,\n): Session {\n const session = {};\n\n let expiresAt = expirationDate;\n\n defineStaticProperty<Session['id']>(session, 'id', sessionId);\n\n defineStaticProperty<Session['destroy']>(session, 'destroy', async () => {\n delete (req as any).session;\n await store.destroy(sessionId);\n });\n\n defineStaticProperty<Session['regenerate']>(session, 'regenerate', async () => {\n await store.destroy(sessionId);\n req.session = makeSession(await generateSessionId(), req, store, null, maxAge);\n });\n\n defineStaticProperty<Session['getExpirationDate']>(session, 'getExpirationDate', () => {\n if (expiresAt == null) {\n expiresAt = new Date(Date.now() + maxAge);\n }\n return expiresAt;\n });\n\n defineStaticProperty<Session['setExpiration']>(session, 'setExpiration', (expiration) => {\n if (typeof expiration === 'number') {\n expiresAt = new Date(Date.now() + expiration);\n } else {\n expiresAt = expiration;\n }\n });\n\n return session as Session;\n}\n\nexport function hashSession(session: Session): string {\n const str = JSON.stringify(session);\n return crypto.createHash('sha1').update(str, 'utf8').digest('hex');\n}\n\nfunction defineStaticProperty<T>(obj: object, name: string, fn: T) {\n Object.defineProperty(obj, name, {\n configurable: false,\n enumerable: false,\n writable: false,\n value: fn,\n });\n}\n\nexport function truncateExpirationDate(date: Date) {\n const time = date.getTime();\n const truncatedTime = Math.floor(time / 1000) * 1000;\n return new Date(truncatedTime);\n}\n"]}
@@ -1,9 +1,9 @@
1
- import { Server } from 'node:http';
2
- import express from 'express';
1
+ import { type Server } from 'node:http';
2
+ import { type Express } from 'express';
3
3
  interface WithServerContext {
4
4
  server: Server;
5
5
  port: number;
6
6
  url: string;
7
7
  }
8
- export declare function withServer(app: express.Express, fn: (ctx: WithServerContext) => Promise<void>): Promise<void>;
8
+ export declare function withServer(app: Express, fn: (ctx: WithServerContext) => Promise<void>): Promise<void>;
9
9
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAoB,EACpB,EAA6C;IAE7C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;IAE5B,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,EAAE,CAAC;YACP,MAAM;YACN,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC;YAC3B,GAAG,EAAE,oBAAoB,aAAa,CAAC,MAAM,CAAC,EAAE;SACjD,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAEjC,uBAAuB;IACvB,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAEzD,uBAAuB;IACvB,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAElF,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC","sourcesContent":["import { Server } from 'node:http';\n\nimport express from 'express';\n\ninterface WithServerContext {\n server: Server;\n port: number;\n url: string;\n}\n\nexport async function withServer(\n app: express.Express,\n fn: (ctx: WithServerContext) => Promise<void>,\n) {\n const server = app.listen();\n\n await new Promise<void>((resolve, reject) => {\n server.on('listening', () => resolve());\n server.on('error', (err) => reject(err));\n });\n\n try {\n await fn({\n server,\n port: getServerPort(server),\n url: `http://localhost:${getServerPort(server)}`,\n });\n } finally {\n server.close();\n }\n}\n\nfunction getServerPort(server: Server): number {\n const address = server.address();\n\n // istanbul ignore next\n if (!address) throw new Error('Server is not listening');\n\n // istanbul ignore next\n if (typeof address === 'string') throw new Error('Server is listening on a pipe');\n\n return address.port;\n}\n"]}
1
+ {"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,GAAY,EAAE,EAA6C;IAC1F,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;IAE5B,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1C,MAAM,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,MAAM,EAAE,CAAC;YACP,MAAM;YACN,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC;YAC3B,GAAG,EAAE,oBAAoB,aAAa,CAAC,MAAM,CAAC,EAAE;SACjD,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,MAAc;IACnC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAEjC,uBAAuB;IACvB,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAEzD,uBAAuB;IACvB,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAElF,OAAO,OAAO,CAAC,IAAI,CAAC;AACtB,CAAC","sourcesContent":["import { type Server } from 'node:http';\n\nimport { type Express } from 'express';\n\ninterface WithServerContext {\n server: Server;\n port: number;\n url: string;\n}\n\nexport async function withServer(app: Express, fn: (ctx: WithServerContext) => Promise<void>) {\n const server = app.listen();\n\n await new Promise<void>((resolve, reject) => {\n server.on('listening', () => resolve());\n server.on('error', (err) => reject(err));\n });\n\n try {\n await fn({\n server,\n port: getServerPort(server),\n url: `http://localhost:${getServerPort(server)}`,\n });\n } finally {\n server.close();\n }\n}\n\nfunction getServerPort(server: Server): number {\n const address = server.address();\n\n // istanbul ignore next\n if (!address) throw new Error('Server is not listening');\n\n // istanbul ignore next\n if (typeof address === 'string') throw new Error('Server is listening on a pipe');\n\n return address.port;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prairielearn/session",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -15,8 +15,8 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@types/express": "^4.17.21",
18
- "cookie": "^0.6.0",
19
- "cookie-signature": "^1.2.1",
18
+ "cookie": "^0.7.2",
19
+ "cookie-signature": "^1.2.2",
20
20
  "express-async-handler": "^1.2.0",
21
21
  "on-headers": "^1.0.2",
22
22
  "uid-safe": "^2.1.5"
@@ -24,24 +24,24 @@
24
24
  "devDependencies": {
25
25
  "@prairielearn/express-test-utils": "^2.0.0",
26
26
  "@prairielearn/tsconfig": "^0.0.0",
27
- "@types/chai": "^4.3.17",
27
+ "@types/chai": "^5.0.1",
28
28
  "@types/cookie": "^0.6.0",
29
29
  "@types/cookie-signature": "^1.1.2",
30
- "@types/node": "^20.14.15",
30
+ "@types/node": "^20.17.5",
31
31
  "@types/node-fetch": "^2.6.11",
32
32
  "@types/on-headers": "^1.0.3",
33
33
  "@types/set-cookie-parser": "^2.4.10",
34
34
  "@types/uid-safe": "^2.1.5",
35
35
  "c8": "^10.1.2",
36
- "chai": "^5.1.1",
37
- "express": "^4.19.2",
36
+ "chai": "^5.1.2",
37
+ "express": "^4.21.1",
38
38
  "fetch-cookie": "^3.0.1",
39
- "mocha": "^10.7.3",
39
+ "mocha": "^10.8.2",
40
40
  "node-fetch": "^3.3.2",
41
- "set-cookie-parser": "^2.7.0",
41
+ "set-cookie-parser": "^2.7.1",
42
42
  "source-map-support": "^0.5.21",
43
- "tsx": "^4.17.0",
44
- "typescript": "^5.5.4"
43
+ "tsx": "^4.19.2",
44
+ "typescript": "^5.6.3"
45
45
  },
46
46
  "c8": {
47
47
  "reporter": [
@@ -1,4 +1,4 @@
1
- import { SessionStore, SessionStoreData } from './store.js';
1
+ import { type SessionStore, type SessionStoreData } from './store.js';
2
2
 
3
3
  export class MemoryStore implements SessionStore {
4
4
  private sessions = new Map<string, { expiresAt: Date; data: string }>();
package/src/session.ts CHANGED
@@ -3,7 +3,7 @@ import crypto from 'node:crypto';
3
3
  import type { Request } from 'express';
4
4
  import uid from 'uid-safe';
5
5
 
6
- import { SessionStore } from './store.js';
6
+ import { type SessionStore } from './store.js';
7
7
 
8
8
  export interface Session {
9
9
  id: string;
package/src/test-utils.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { Server } from 'node:http';
1
+ import { type Server } from 'node:http';
2
2
 
3
- import express from 'express';
3
+ import { type Express } from 'express';
4
4
 
5
5
  interface WithServerContext {
6
6
  server: Server;
@@ -8,10 +8,7 @@ interface WithServerContext {
8
8
  url: string;
9
9
  }
10
10
 
11
- export async function withServer(
12
- app: express.Express,
13
- fn: (ctx: WithServerContext) => Promise<void>,
14
- ) {
11
+ export async function withServer(app: Express, fn: (ctx: WithServerContext) => Promise<void>) {
15
12
  const server = app.listen();
16
13
 
17
14
  await new Promise<void>((resolve, reject) => {