Skip to content

Commit 87bbd17

Browse files
committed
in APIs remove fallbacks to false and fallback to undefined. Update documentation
1 parent 3c9aa2a commit 87bbd17

6 files changed

Lines changed: 37 additions & 46 deletions

File tree

lib/api/addresses.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
245245
results: (listing.results || []).map(addressData => {
246246
let values = {
247247
id: addressData._id.toString(),
248-
name: addressData.name || false,
248+
name: addressData.name || undefined,
249249
address: addressData.address,
250250
user: addressData.user && addressData.user.toString(),
251251
forwarded: !!addressData.targets,
@@ -704,7 +704,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
704704
results: addresses.map(addressData => {
705705
let values = {
706706
id: addressData._id.toString(),
707-
name: addressData.name || false,
707+
name: addressData.name || undefined,
708708
address: addressData.address,
709709
main: addressData.address === userData.address,
710710
tags: addressData.tags || [],
@@ -747,7 +747,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
747747
model: Joi.object({
748748
success: successRes,
749749
id: addressId,
750-
name: Joi.string().required().description('Identity name'),
750+
name: Joi.string().description('Identity name'),
751751
address: addressEmail,
752752
main: booleanSchema.required().description('Indicates if this is the default address for the User'),
753753
created: Joi.date().required().description('Datestring of the time the address was created'),
@@ -850,7 +850,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
850850
let value = {
851851
success: true,
852852
id: addressData._id.toString(),
853-
name: addressData.name || false,
853+
name: addressData.name || undefined,
854854
address: addressData.address,
855855
main: addressData.address === userData.address,
856856
tags: addressData.tags || [],
@@ -1428,7 +1428,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
14281428
success: true,
14291429

14301430
results: addresses.map(addressData => {
1431-
let name = addressData.name || false;
1431+
let name = addressData.name || undefined;
14321432
try {
14331433
// try to decode
14341434
if (name) {
@@ -1439,7 +1439,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
14391439
}
14401440
return {
14411441
id: addressData._id.toString(),
1442-
name: addressData.name || false,
1442+
name: addressData.name || undefined,
14431443
address: addressData.address
14441444
};
14451445
})
@@ -2167,7 +2167,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
21672167
success: successRes,
21682168
id: addressId,
21692169
address: addressEmail,
2170-
name: Joi.string().required().description('Identity name'),
2170+
name: Joi.string().description('Identity name'),
21712171
targets: Joi.array().items(Joi.string()).description('List of forwarding targets'),
21722172
limits: AddressLimits,
21732173
autoreply: AutoreplyInfo,
@@ -2254,7 +2254,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
22542254
const values = {
22552255
success: true,
22562256
id: addressData._id.toString(),
2257-
name: addressData.name || false,
2257+
name: addressData.name || undefined,
22582258
address: addressData.address,
22592259
targets: addressData.targets && addressData.targets.map(t => t.value),
22602260
limits: {

lib/api/asps.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ module.exports = (db, server, userHandler) => {
5050
.required()
5151
.description('Allowed scopes for the Application Password'),
5252
lastUse: Joi.object({
53-
time: Joi.date().required().description('Datestring of last use or false if password has not been used'),
54-
event: Joi.string().required().description('Event ID of the security log for the last authentication')
53+
time: Joi.date().description('Datestring of last use or not present if password has not been used'),
54+
event: Joi.string().description('Event ID of the security log for the last authentication')
5555
})
5656
.required()
5757
.$_setFlag('objectName', 'LastUse')
@@ -170,8 +170,8 @@ module.exports = (db, server, userHandler) => {
170170
description: asp.description,
171171
scopes: asp.scopes.includes('*') ? [...consts.SCOPES] : asp.scopes,
172172
lastUse: {
173-
time: asp.used || false,
174-
event: asp.authEvent || false
173+
time: asp.used || undefined,
174+
event: asp.authEvent || undefined
175175
},
176176
expires: asp.expires,
177177
created: asp.created
@@ -209,8 +209,8 @@ module.exports = (db, server, userHandler) => {
209209
.required()
210210
.description('Allowed scopes for the Application Password'),
211211
lastUse: Joi.object({
212-
time: Joi.date().required().description('Datestring of last use or false if password has not been used'),
213-
event: Joi.string().required().description('Event ID of the security log for the last authentication')
212+
time: Joi.date().description('Datestring of last use or not present if password has not been used'),
213+
event: Joi.string().description('Event ID of the security log for the last authentication')
214214
})
215215
.required()
216216
.$_setFlag('objectName', 'LastUse')
@@ -286,8 +286,8 @@ module.exports = (db, server, userHandler) => {
286286
description: aspData.description,
287287
scopes: aspData.scopes.includes('*') ? [...consts.SCOPES] : aspData.scopes,
288288
lastUse: {
289-
time: aspData.used || false,
290-
event: aspData.authEvent || false
289+
time: aspData.used || undefined,
290+
event: aspData.authEvent || undefined
291291
},
292292
expires: asp.expires,
293293
created: aspData.created

lib/api/autoreply.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,9 @@ module.exports = (db, server) => {
181181
.trim()
182182
.max(128 * 1024)
183183
.description('HTML formatted content of the autoreply message'),
184-
start: Joi.date()
185-
.empty('')
186-
.allow(false)
187-
.description('Datestring of the start of the autoreply or boolean false to disable start checks'),
188-
end: Joi.date().empty('').allow(false).description('Datestring of the end of the autoreply or boolean false to disable end checks'),
189-
created: Joi.date().required().description('Datestring of when the Autoreply was created')
184+
start: Joi.date().empty('').description('Datestring of the start of the autoreply or boolean false to disable start checks'),
185+
end: Joi.date().empty('').description('Datestring of the end of the autoreply or boolean false to disable end checks'),
186+
created: Joi.date().description('Datestring of when the Autoreply was created')
190187
}).$_setFlag('objectName', 'GetAutoreplyResponse')
191188
}
192189
}
@@ -236,9 +233,9 @@ module.exports = (db, server) => {
236233
subject: entry.subject || '',
237234
text: entry.text || '',
238235
html: entry.html || '',
239-
start: entry.start || false,
240-
end: entry.end || false,
241-
created: entry.created || entry._id?.getTimestamp() || false
236+
start: entry.start || undefined,
237+
end: entry.end || undefined,
238+
created: entry.created || entry._id?.getTimestamp() || undefined
242239
});
243240
})
244241
);

lib/api/storage.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const ObjectId = require('mongodb').ObjectId;
66
const tools = require('../tools');
77
const roles = require('../roles');
88
const consts = require('../consts');
9-
const { nextPageCursorSchema, previousPageCursorSchema, pageNrSchema, sessSchema, sessIPSchema, booleanSchema } = require('../schemas');
9+
const { nextPageCursorSchema, previousPageCursorSchema, pageNrSchema, sessSchema, sessIPSchema } = require('../schemas');
1010
const { userId } = require('../schemas/request/general-schemas');
1111
const { successRes, totalRes, pageRes, previousCursorRes, nextCursorRes } = require('../schemas/response/general-schemas');
1212

@@ -157,14 +157,8 @@ module.exports = (db, server, storageHandler) => {
157157
.items(
158158
Joi.object({
159159
id: Joi.string().required().description('File ID'),
160-
filename: Joi.alternatives()
161-
.try(Joi.string().required(), booleanSchema.required())
162-
.required()
163-
.description('Filename. False if none'),
164-
contentType: Joi.alternatives()
165-
.try(Joi.string().required(), booleanSchema.required())
166-
.required()
167-
.description('Content-Type of the file. False if none'),
160+
filename: Joi.string().description('Filename'),
161+
contentType: Joi.string().description('Content-Type of the file'),
168162
cid: Joi.string().description('Content ID'),
169163
size: Joi.number().required().description('File size'),
170164
created: Joi.date().required().description('Created datestring'),
@@ -297,8 +291,8 @@ module.exports = (db, server, storageHandler) => {
297291
nextCursor: listing.hasNext ? listing.next : false,
298292
results: (listing.results || []).map(fileData => ({
299293
id: fileData._id.toString(),
300-
filename: fileData.filename || false,
301-
contentType: fileData.contentType || false,
294+
filename: fileData.filename || undefined,
295+
contentType: fileData.contentType || undefined,
302296
cid: fileData.metadata?.cid,
303297
size: fileData.length,
304298
created: fileData.uploadDate.toISOString(),

lib/api/users.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
793793
username: Joi.string().required().description('Username of the User'),
794794
name: Joi.string().required().description('Name of the User'),
795795
address: Joi.string().required().description('Main email address of the User'),
796-
retention: Joi.number().required().description('Default retention time (in ms). false if not enabled'),
796+
retention: Joi.number().description('Default retention time (in ms). Not present if not enabled'),
797797
enabled2fa: Joi.array().items(Joi.string()).required().description('List of enabled 2FA methods'),
798798
autoreply: booleanSchema
799799
.required()
@@ -814,7 +814,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
814814
.required()
815815
.description('Custom internal metadata object set for this user. Not available for user-role tokens'),
816816
targets: Joi.array().items(Joi.string()).required().description('List of forwarding targets'),
817-
mtaRelay: Joi.string().required().description('MTA Relay url'),
817+
mtaRelay: Joi.string().description('MTA Relay url'),
818818
spamLevel: Joi.number()
819819
.required()
820820
.description('Relative scale for detecting spam. 0 means that everything is spam, 100 means that nothing is spam'),
@@ -1073,7 +1073,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
10731073
address: userData.address,
10741074

10751075
language: userData.language,
1076-
retention: userData.retention || false,
1076+
retention: userData.retention || undefined,
10771077

10781078
enabled2fa: tools.getEnabled2fa(userData.enabled2fa),
10791079
autoreply: !!userData.autoreply,
@@ -1092,7 +1092,7 @@ module.exports = (db, server, userHandler, settingsHandler) => {
10921092
.map(target => target.value)
10931093
.filter(target => target),
10941094

1095-
mtaRelay: userData.mtaRelay?.value || false,
1095+
mtaRelay: userData.mtaRelay?.value || undefined,
10961096

10971097
limits: {
10981098
quota: {

lib/schemas/response/addresses-schemas.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { addressId, addressEmail } = require('../request/general-schemas');
66

77
const GetAddressesResult = Joi.object({
88
id: Joi.string().required().description('ID of the Address'),
9-
name: Joi.string().required().description('Identity name'),
9+
name: Joi.string().description('Identity name'),
1010
address: Joi.string().required().description('E-mail address string'),
1111
user: Joi.string().required().description('User ID this address belongs to if this is a User address'),
1212
forwarded: booleanSchema.required().description('If true then it is a forwarded address'),
@@ -19,7 +19,7 @@ const GetAddressesResult = Joi.object({
1919

2020
const GetUserAddressesResult = Joi.object({
2121
id: addressId,
22-
name: Joi.string().required().description('Identity name'),
22+
name: Joi.string().description('Identity name'),
2323
address: addressEmail,
2424
main: booleanSchema.required().description('Indicates if this is the default address for the User'),
2525
created: Joi.date().required().description('Datestring of the time the address was created'),
@@ -50,10 +50,10 @@ const AddressLimits = Joi.object({
5050

5151
const AutoreplyInfo = Joi.object({
5252
status: booleanSchema.required().description('If true, then autoreply is enabled for this address'),
53-
name: Joi.string().required().description('Name that is used for the From: header in autoreply message'),
54-
subject: Joi.string().required().description('Autoreply subject line'),
55-
text: Joi.string().required().description('Autoreply plaintext content'),
56-
html: Joi.string().required().description('Autoreply HTML content')
53+
name: Joi.string().description('Name that is used for the From: header in autoreply message'),
54+
subject: Joi.string().description('Autoreply subject line'),
55+
text: Joi.string().description('Autoreply plaintext content'),
56+
html: Joi.string().description('Autoreply HTML content')
5757
})
5858
.required()
5959
.description('Autoreply information')

0 commit comments

Comments
 (0)