@prairielearn/flash 2.0.12 → 2.0.14

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,21 @@
1
1
  # @prairielearn/flash
2
2
 
3
+ ## 2.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 03f1008: Upgrade all JavaScript dependencies
8
+ - Updated dependencies [03f1008]
9
+ - @prairielearn/html@4.0.12
10
+
11
+ ## 2.0.13
12
+
13
+ ### Patch Changes
14
+
15
+ - 984dc62: Upgrade all JavaScript dependencies
16
+ - Updated dependencies [984dc62]
17
+ - @prairielearn/html@4.0.11
18
+
3
19
  ## 2.0.12
4
20
 
5
21
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Request, Response, NextFunction } from 'express';
1
+ import type { NextFunction, Request, Response } from 'express';
2
2
  import { type HtmlSafeString } from '@prairielearn/html';
3
3
  export type FlashMessageType = 'notice' | 'success' | 'warning' | 'error';
4
4
  export interface FlashMessage {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD,OAAO,EAAuB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/D,MAAM,GAAG,GAAG,IAAI,iBAAiB,EAAgB,CAAC;AASlD,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,GAAY,EAAE,IAAc,EAAE,IAAkB,EAAE,EAAE;QAC1D,MAAM,YAAY,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC3C,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC;AAID,MAAM,UAAU,KAAK,CACnB,IAA4C,EAC5C,OAAiC;IA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,KAAK,GAAG,EAAE,CAAC;QACrB,CAAC;KACqB,CAAC;AAC3B,CAAC","sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\n\nimport type { Request, Response, NextFunction } from 'express';\n\nimport { type HtmlSafeString, html } from '@prairielearn/html';\n\nconst als = new AsyncLocalStorage<FlashStorage>();\n\nexport type FlashMessageType = 'notice' | 'success' | 'warning' | 'error';\n\nexport interface FlashMessage {\n type: FlashMessageType;\n message: string;\n}\n\nexport function flashMiddleware() {\n return (req: Request, _res: Response, next: NextFunction) => {\n const flashStorage = makeFlashStorage(req);\n als.run(flashStorage, () => next());\n };\n}\n\nexport function flash(type?: FlashMessageType | FlashMessageType[]): FlashMessage[];\nexport function flash(type: FlashMessageType, message: string | HtmlSafeString): void;\nexport function flash(\n type?: FlashMessageType | FlashMessageType[],\n message?: string | HtmlSafeString,\n) {\n const flashStorage = als.getStore();\n if (!flashStorage) {\n throw new Error('flash() must be called within a request');\n }\n\n if (Array.isArray(type)) {\n const messages = type.flatMap((type) => flashStorage.get(type));\n type.forEach((t) => flashStorage.clear(t));\n return messages;\n }\n\n if (type != null && message != null) {\n flashStorage.add(type, message);\n return;\n }\n\n if (type != null) {\n const message = flashStorage.get(type);\n flashStorage.clear(type);\n return message;\n }\n\n const messages = flashStorage.getAll();\n flashStorage.clearAll();\n return messages;\n}\n\ninterface FlashStorage {\n add(type: FlashMessageType, message: string | HtmlSafeString): void;\n get(type: FlashMessageType): FlashMessage[] | null;\n getAll(): FlashMessage[];\n clear(type: FlashMessageType): void;\n clearAll(): void;\n}\n\nfunction makeFlashStorage(req: Request): FlashStorage {\n // The \"flash storage\" object will be stored in `AsyncLocalStorage` for the\n // request. If we start some async I/O during a request (such as opening a\n // database connection or a socket connection to Docker), that would by\n // default keep the async context, and thus the request. This would prevent\n // the request object (and any data associated with it) from being garbage\n // collected. We use a `WeakRef` to fix this.\n //\n // This should always be safe, as the request object won't be garbage\n // collected until the response has been sent, and we should never be reading\n // or writing flash messages after the response has been sent.\n const reqRef = new WeakRef(req);\n\n function getSession() {\n const req = reqRef.deref();\n if (!req) throw new Error('Request has been garbage collected');\n const session = (req as any).session;\n if (!session) throw new Error('No session found on request');\n return session;\n }\n\n return {\n add(type: FlashMessageType, message: string | HtmlSafeString) {\n const session = getSession();\n session.flash ??= [];\n session.flash.push({ type, message: html`${message}`.toString() });\n },\n get(type: FlashMessageType) {\n const session = getSession();\n const messages = session.flash ?? [];\n return messages.filter((message: FlashMessage) => message.type === type);\n },\n getAll() {\n const session = getSession();\n return session.flash ?? [];\n },\n clear(type: FlashMessageType) {\n const session = getSession();\n session.flash = session.flash?.filter((message: FlashMessage) => message.type !== type) ?? [];\n },\n clearAll() {\n const session = getSession();\n session.flash = [];\n },\n } satisfies FlashStorage;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAIrD,OAAO,EAAuB,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/D,MAAM,GAAG,GAAG,IAAI,iBAAiB,EAAgB,CAAC;AASlD,MAAM,UAAU,eAAe;IAC7B,OAAO,CAAC,GAAY,EAAE,IAAc,EAAE,IAAkB,EAAE,EAAE;QAC1D,MAAM,YAAY,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAC3C,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC;AAID,MAAM,UAAU,KAAK,CACnB,IAA4C,EAC5C,OAAiC;IAEjC,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IACpC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;Q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C,6BAA6B,CAAC,CAAC;QAC7D,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,OAAO;QACL,GAAG,CAAC,IAAsB,EAAE,OAAgC;YAC1D,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,KAAK,EAAE,CAAC;YACrB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAA,GAAG,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,GAAG,CAAC,IAAsB;YACxB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;YACrC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAqB,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAC3E,CAAC;QACD,MAAM;YACJ,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAC7B,OAAO,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QAC7B,CAAC;QACD,KAAK,CAAC,IAAsB;YAC1B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAqB,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;QAChG,CAAC;QACD,QAAQ;YACN,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;YAC7B,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;QACrB,CAAC;KACqB,CAAC;AAC3B,CAAC","sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\n\nimport type { NextFunction, Request, Response } from 'express';\n\nimport { type HtmlSafeString, html } from '@prairielearn/html';\n\nconst als = new AsyncLocalStorage<FlashStorage>();\n\nexport type FlashMessageType = 'notice' | 'success' | 'warning' | 'error';\n\nexport interface FlashMessage {\n type: FlashMessageType;\n message: string;\n}\n\nexport function flashMiddleware() {\n return (req: Request, _res: Response, next: NextFunction) => {\n const flashStorage = makeFlashStorage(req);\n als.run(flashStorage, () => next());\n };\n}\n\nexport function flash(type?: FlashMessageType | FlashMessageType[]): FlashMessage[];\nexport function flash(type: FlashMessageType, message: string | HtmlSafeString): void;\nexport function flash(\n type?: FlashMessageType | FlashMessageType[],\n message?: string | HtmlSafeString,\n) {\n const flashStorage = als.getStore();\n if (!flashStorage) {\n throw new Error('flash() must be called within a request');\n }\n\n if (Array.isArray(type)) {\n const messages = type.flatMap((type) => flashStorage.get(type));\n type.forEach((t) => flashStorage.clear(t));\n return messages;\n }\n\n if (type != null && message != null) {\n flashStorage.add(type, message);\n return;\n }\n\n if (type != null) {\n const message = flashStorage.get(type);\n flashStorage.clear(type);\n return message;\n }\n\n const messages = flashStorage.getAll();\n flashStorage.clearAll();\n return messages;\n}\n\ninterface FlashStorage {\n add(type: FlashMessageType, message: string | HtmlSafeString): void;\n get(type: FlashMessageType): FlashMessage[] | null;\n getAll(): FlashMessage[];\n clear(type: FlashMessageType): void;\n clearAll(): void;\n}\n\nfunction makeFlashStorage(req: Request): FlashStorage {\n // The \"flash storage\" object will be stored in `AsyncLocalStorage` for the\n // request. If we start some async I/O during a request (such as opening a\n // database connection or a socket connection to Docker), that would by\n // default keep the async context, and thus the request. This would prevent\n // the request object (and any data associated with it) from being garbage\n // collected. We use a `WeakRef` to fix this.\n //\n // This should always be safe, as the request object won't be garbage\n // collected until the response has been sent, and we should never be reading\n // or writing flash messages after the response has been sent.\n const reqRef = new WeakRef(req);\n\n function getSession() {\n const req = reqRef.deref();\n if (!req) throw new Error('Request has been garbage collected');\n const session = (req as any).session;\n if (!session) throw new Error('No session found on request');\n return session;\n }\n\n return {\n add(type: FlashMessageType, message: string | HtmlSafeString) {\n const session = getSession();\n session.flash ??= [];\n session.flash.push({ type, message: html`${message}`.toString() });\n },\n get(type: FlashMessageType) {\n const session = getSession();\n const messages = session.flash ?? [];\n return messages.filter((message: FlashMessage) => message.type === type);\n },\n getAll() {\n const session = getSession();\n return session.flash ?? [];\n },\n clear(type: FlashMessageType) {\n const session = getSession();\n session.flash = session.flash?.filter((message: FlashMessage) => message.type !== type) ?? [];\n },\n clearAll() {\n const session = getSession();\n session.flash = [];\n },\n } satisfies FlashStorage;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { assert } from 'chai';
2
2
  import { html } from '@prairielearn/html';
3
- import { flashMiddleware, flash } from './index.js';
3
+ import { flash, flashMiddleware } from './index.js';
4
4
  describe('flash', () => {
5
5
  it('throws an error if no session present', () => {
6
6
  assert.throw(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEpD,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,eAAe,EAAE,CAAC,EAAS,EAAE,EAAS,EAAE,GAAG,EAAE;gBAC3C,KAAK,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,6BAA6B,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,KAAK,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;QACjC,CAAC,EAAE,yCAAyC,CAAC,CAAC;QAC9C,MAAM,CAAC,KAAK,CAAC,GAA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AG,EAAE;QAC7C,MAAM,GAAG,GAAG;YACV,OAAO,EAAE,EAAE;SACL,CAAC;QACT,MAAM,GAAG,GAAG,EAAS,CAAC;QAEtB,eAAe,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;YAC/B,KAAK,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;YAC/B,KAAK,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;YACnC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAA,YAAY,GAAG,YAAY,CAAC,CAAC;YAElD,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC;YACtF,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;gBACrC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,wBAAwB,EAAE;aACrD,CAAC,CAAC;YACH,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE;gBACvC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,0BAA0B,EAAE;aACzD,CAAC,CAAC;YAEH,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;YACtC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;YACrC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;YACvC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert } from 'chai';\n\nimport { html } from '@prairielearn/html';\n\nimport { flashMiddleware, flash } from './index.js';\n\ndescribe('flash', () => {\n it('throws an error if no session present', () => {\n assert.throw(() => {\n flashMiddleware()({} as any, {} as any, () => {\n flash('notice', 'Hello world');\n });\n }, 'No session found on request');\n });\n\n it('throws an error when middleware is not used', () => {\n assert.throw(() => {\n flash('notice', 'Hello world');\n }, 'flash() must be called within a request');\n assert.throw(() => {\n flash('notice', html`<p>hello ${'&'} world</p>`);\n }, 'flash() must be called within a request');\n });\n\n it('adds a flash using string message', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n\n assert.sameDeepMembers(flash(), [{ type: 'notice', message: 'hello world' }]);\n });\n });\n\n it('adds a flash and escapes unsafe HTML', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', '<b>hello world</b>');\n\n assert.sameDeepMembers(flash(), [\n { type: 'notice', message: '&lt;b&gt;hello world&lt;/b&gt;' },\n ]);\n });\n });\n\n it('adds a flash with HTML-safe message', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash(), [{ type: 'notice', message: '<p>hello &amp; world</p>' }]);\n });\n });\n\n it('stores multiples flashes with the same type', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n flash('notice', '<< goodbye world');\n flash('notice', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash(), [\n { type: 'notice', message: 'hello world' },\n { type: 'notice', message: '&lt;&lt; goodbye world' },\n { type: 'notice', message: '<p>hello &amp; world</p>' },\n ]);\n });\n });\n\n it('returns flash message for a given type', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n flash('error', '<< goodbye world');\n flash('success', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash('notice'), [{ type: 'notice', message: 'hello world' }]);\n assert.sameDeepMembers(flash('error'), [\n { type: 'error', message: '&lt;&lt; goodbye world' },\n ]);\n assert.sameDeepMembers(flash('success'), [\n { type: 'success', message: '<p>hello &amp; world</p>' },\n ]);\n });\n });\n\n it('returns all flashes', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n flash('error', '<< goodbye world');\n flash('success', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash(), [\n { type: 'notice', message: 'hello world' },\n { type: 'error', message: '&lt;&lt; goodbye world' },\n { type: 'success', message: '<p>hello &amp; world</p>' },\n ]);\n });\n });\n\n it('clears flash after it has been read', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n flash('error', '<< goodbye world');\n flash('success', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash('notice'), [{ type: 'notice', message: 'hello world' }]);\n assert.sameDeepMembers(flash('error'), [\n { type: 'error', message: '&lt;&lt; goodbye world' },\n ]);\n assert.sameDeepMembers(flash('success'), [\n { type: 'success', message: '<p>hello &amp; world</p>' },\n ]);\n\n assert.deepEqual(flash('notice'), []);\n assert.deepEqual(flash('error'), []);\n assert.deepEqual(flash('success'), []);\n assert.isEmpty(flash());\n });\n });\n});\n"]}
1
+ {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpD,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,eAAe,EAAE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YACtC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;YACrC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;YACvC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert } from 'chai';\n\nimport { html } from '@prairielearn/html';\n\nimport { flash, flashMiddleware } from './index.js';\n\ndescribe('flash', () => {\n it('throws an error if no session present', () => {\n assert.throw(() => {\n flashMiddleware()({} as any, {} as any, () => {\n flash('notice', 'Hello world');\n });\n }, 'No session found on request');\n });\n\n it('throws an error when middleware is not used', () => {\n assert.throw(() => {\n flash('notice', 'Hello world');\n }, 'flash() must be called within a request');\n assert.throw(() => {\n flash('notice', html`<p>hello ${'&'} world</p>`);\n }, 'flash() must be called within a request');\n });\n\n it('adds a flash using string message', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n\n assert.sameDeepMembers(flash(), [{ type: 'notice', message: 'hello world' }]);\n });\n });\n\n it('adds a flash and escapes unsafe HTML', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', '<b>hello world</b>');\n\n assert.sameDeepMembers(flash(), [\n { type: 'notice', message: '&lt;b&gt;hello world&lt;/b&gt;' },\n ]);\n });\n });\n\n it('adds a flash with HTML-safe message', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash(), [{ type: 'notice', message: '<p>hello &amp; world</p>' }]);\n });\n });\n\n it('stores multiples flashes with the same type', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n flash('notice', '<< goodbye world');\n flash('notice', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash(), [\n { type: 'notice', message: 'hello world' },\n { type: 'notice', message: '&lt;&lt; goodbye world' },\n { type: 'notice', message: '<p>hello &amp; world</p>' },\n ]);\n });\n });\n\n it('returns flash message for a given type', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n flash('error', '<< goodbye world');\n flash('success', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash('notice'), [{ type: 'notice', message: 'hello world' }]);\n assert.sameDeepMembers(flash('error'), [\n { type: 'error', message: '&lt;&lt; goodbye world' },\n ]);\n assert.sameDeepMembers(flash('success'), [\n { type: 'success', message: '<p>hello &amp; world</p>' },\n ]);\n });\n });\n\n it('returns all flashes', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n flash('error', '<< goodbye world');\n flash('success', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash(), [\n { type: 'notice', message: 'hello world' },\n { type: 'error', message: '&lt;&lt; goodbye world' },\n { type: 'success', message: '<p>hello &amp; world</p>' },\n ]);\n });\n });\n\n it('clears flash after it has been read', () => {\n const req = {\n session: {},\n } as any;\n const res = {} as any;\n\n flashMiddleware()(req, res, () => {\n flash('notice', 'hello world');\n flash('error', '<< goodbye world');\n flash('success', html`<p>hello ${'&'} world</p>`);\n\n assert.sameDeepMembers(flash('notice'), [{ type: 'notice', message: 'hello world' }]);\n assert.sameDeepMembers(flash('error'), [\n { type: 'error', message: '&lt;&lt; goodbye world' },\n ]);\n assert.sameDeepMembers(flash('success'), [\n { type: 'success', message: '<p>hello &amp; world</p>' },\n ]);\n\n assert.deepEqual(flash('notice'), []);\n assert.deepEqual(flash('error'), []);\n assert.deepEqual(flash('success'), []);\n assert.isEmpty(flash());\n });\n });\n});\n"]}
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@prairielearn/flash",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "type": "module",
5
- "main": "dist/index.js",
6
5
  "repository": {
7
6
  "type": "git",
8
7
  "url": "https://github.com/PrairieLearn/PrairieLearn.git",
9
8
  "directory": "packages/flash"
10
9
  },
10
+ "main": "dist/index.js",
11
11
  "scripts": {
12
12
  "build": "tsc",
13
13
  "dev": "tsc --watch --preserveWatchOutput",
14
14
  "test": "c8 mocha src/**/*.test.ts"
15
15
  },
16
16
  "dependencies": {
17
- "@prairielearn/html": "^4.0.10",
17
+ "@prairielearn/html": "^4.0.12",
18
18
  "@types/express": "^4.17.21"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@prairielearn/tsconfig": "^0.0.0",
22
- "@types/node": "^20.17.23",
22
+ "@types/node": "^20.17.30",
23
23
  "c8": "^10.1.3",
24
24
  "chai": "^5.2.0",
25
25
  "mocha": "^11.1.0",
package/src/index.test.ts CHANGED
@@ -2,7 +2,7 @@ import { assert } from 'chai';
2
2
 
3
3
  import { html } from '@prairielearn/html';
4
4
 
5
- import { flashMiddleware, flash } from './index.js';
5
+ import { flash, flashMiddleware } from './index.js';
6
6
 
7
7
  describe('flash', () => {
8
8
  it('throws an error if no session present', () => {
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
2
 
3
- import type { Request, Response, NextFunction } from 'express';
3
+ import type { NextFunction, Request, Response } from 'express';
4
4
 
5
5
  import { type HtmlSafeString, html } from '@prairielearn/html';
6
6