Skip to content

Commit

Permalink
Add clarifying comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Powersource committed Nov 24, 2023
1 parent 3cc8296 commit 942eaa9
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const get = require('lodash.get')
const isString = (t) => (typeof t === 'string')
const isEncrypted = isString

module.exports = {
name: 'recpsGuard',
Expand All @@ -15,19 +14,26 @@ module.exports = {
const [input, cb] = args

if (get(input, ['options', 'allowPublic']) === true) {
// allowPublic and has recps, disallowed
if (hasRecps(input.content)) {
return cb(new Error('recps-guard: should not have recps && allowPublic, check your code'))
}

// allowPublic and no recps, allowed
return publish(input.content, cb)
} else {
// without allowPublic, content isn't nested
const content = input

// no allowPublic and has recps/can publish without recps, allowed
if (
isEncrypted(input) ||
hasRecps(input) ||
allowedTypes.has(input.type)
) return publish(input, cb)
isString(content) ||
hasRecps(content) ||
allowedTypes.has(content.type)
) return publish(content, cb)

return cb(new Error(`recps-guard: public messages of type "${input.type}" not allowed`))
// no allowPublic and no recps, disallowed
return cb(new Error(`recps-guard: public messages of type "${content.type}" not allowed`))
}
}

Expand All @@ -48,7 +54,7 @@ module.exports = {

if (
input.encryptionFormat !== undefined ||
isEncrypted(input.content) ||
isString(input.content) ||
(hasRecps(input.content) && input.allowPublic !== true) ||
allowedTypes.has(input.content.type)
) {
Expand Down Expand Up @@ -109,7 +115,3 @@ function hasRecps (content) {

return true
}

function isAllowPublic2 (input) {
return
}

0 comments on commit 942eaa9

Please sign in to comment.