mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-03 14:19:01 +02:00
a9a28a13f5
[web] Extend `AsyncLocalStorage` to SAML linking in route, clear `AsyncLocalStorage` on email updates, await analytics helper on email updates, GitOrigin-RevId: 86a51e6800a4b954ff81a2d977edf1401064dda4
39 lines
829 B
JavaScript
39 lines
829 B
JavaScript
// @ts-check
|
|
const { AsyncLocalStorage } = require('node:async_hooks')
|
|
|
|
/**
|
|
* @typedef {Object} RequestContext
|
|
* @property {Object.<string, array>} [userFullEmails] - Dictionary mapping userId to an array of full emails
|
|
*/
|
|
|
|
/** @type {AsyncLocalStorage<RequestContext>} */
|
|
const asyncLocalStorage = new AsyncLocalStorage()
|
|
|
|
/**
|
|
* @param {import("express").Request} req
|
|
* @param {import("express").Response} res
|
|
* @param {import("express").NextFunction} next
|
|
*/
|
|
function middleware(req, res, next) {
|
|
asyncLocalStorage.run({}, next)
|
|
}
|
|
|
|
/**
|
|
* Remove a key from the AsyncLocalStorage cache
|
|
*
|
|
* @param {string} key
|
|
*/
|
|
function removeItem(key) {
|
|
const store = asyncLocalStorage.getStore()
|
|
|
|
if (store?.[key]) {
|
|
delete store[key]
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
middleware,
|
|
storage: asyncLocalStorage,
|
|
removeItem,
|
|
}
|