Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 3x 3x 116x 24x 34x 60x 60x 60x 3x | /**
* Pieces shared by the membership-request Lambdas (docs/architecture/FLOW_SPACE.md,
* "Membership requests").
*/
const { resolveActiveFlow } = require('../shared/activeFlow')
const CORS_HEADERS = {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
const respond = (statusCode, body) => ({
statusCode,
headers: CORS_HEADERS,
body: JSON.stringify(body)
})
/** Same 404 for an unknown slug and a space that doesn't take requests */
const spaceNotFound = () => respond(404, { error: 'Space not found' })
/** GSI `flowStatusIndex` sort key: a flow's requests of one status, in date order */
const statusKey = (status, date) => `${status}#${date}`
/**
* The flow named in the path, only when it is the caller's verified active
* flow (X-Flow-Id, checked by requirePermission before the handler runs), so a
* permission held in one flow never acts on another flow's requests.
* @returns {Promise<string | null>}
*/
async function verifiedPathFlowId(event) {
const flowId = event.pathParameters?.flowId
const activeFlow = await resolveActiveFlow(event)
return flowId && activeFlow?.flowId === flowId ? flowId : null
}
module.exports = { CORS_HEADERS, respond, spaceNotFound, statusKey, verifiedPathFlowId }
|