/
schemas.coffee
78 lines (64 loc) · 1.89 KB
/
schemas.coffee
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Joi = require 'joi'
router = require 'promise-router'
User = require './models/user'
MIN_SAFE_INTEGER = -9007199254740991
MAX_SAFE_INTEGER = 9007199254740991
assert = (obj, schema) ->
valid = Joi.validate obj, schema, {presence: 'required', convert: false}
if valid.error
throw new router.Error status: 400, detail: valid.error.message
accessToken = Joi.string()
id = Joi.string().regex(
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ # uuid
)
appName = Joi.string().min(1).max(100).regex(/^[\w\-]+$/)
adminUser =
id: User.ADMIN.id
username: User.ADMIN.username
experimentKey: User.ADMIN.id
auth =
accessToken: accessToken
user =
id: id
experimentKey: Joi.string()
experiment =
id: id
apps: Joi.array().min(1).items appName
key: Joi.string().token()
globalPercent: Joi.number()
choices: Joi.array().items Joi.string().token()
weights: Joi.array().optional().items Joi.number()
createdAt: Joi.date().strict(false)
experimentCreate =
apps: experiment.apps
key: experiment.key
globalPercent: experiment.globalPercent.optional()
choices: experiment.choices
weights: experiment.weights.optional()
event =
app: appName
inviterId: id.optional()
event: Joi.string().min(1).max(100).token() # Arbitrary min and max
userTags: Joi.object().optional()
userFields: Joi.object().optional()
isInteractive: Joi.boolean().optional()
keys: Joi.array().items \
Joi.string().min(1).max(100).token() # Arbitrary min and max
strings: Joi.array().items \
Joi.string().min(1).max(1000) # Arbitrary min and max
# Floats are dissalowed currently because influx types are strict
# and require decimals (e.g. 1.0 -> '1' would error)
numbers: Joi.array().items \
Joi.number().integer().min(MIN_SAFE_INTEGER).max(MAX_SAFE_INTEGER)
module.exports = {
assert
id
appName
auth
user
adminUser
accessToken
experiment
experimentCreate
event
}