emailengine-app 2.75.0 → 2.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/release.yaml +24 -19
- package/.github/workflows/test.yml +0 -10
- package/.ncurc.js +14 -2
- package/.release-please-manifest.json +3 -0
- package/CHANGELOG.md +38 -0
- package/README.md +1 -1
- package/config/e2e.toml +1 -1
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +71 -4
- package/lib/address-strategies.js +18 -0
- package/lib/api-reference/code-samples.js +194 -0
- package/lib/api-reference/format.js +179 -0
- package/lib/api-reference/index.js +205 -0
- package/lib/api-reference/model.js +336 -0
- package/lib/api-reference/schema-tree.js +366 -0
- package/lib/api-routes/account-routes.js +117 -37
- package/lib/api-routes/behavior-notes.js +54 -0
- package/lib/api-routes/blocklist-routes.js +9 -9
- package/lib/api-routes/changes-routes.js +6 -4
- package/lib/api-routes/chat-routes.js +3 -3
- package/lib/api-routes/delivery-test-routes.js +24 -6
- package/lib/api-routes/export-routes.js +14 -12
- package/lib/api-routes/gateway-routes.js +11 -11
- package/lib/api-routes/license-routes.js +7 -7
- package/lib/api-routes/mailbox-routes.js +18 -9
- package/lib/api-routes/message-routes.js +55 -35
- package/lib/api-routes/oauth2-app-routes.js +22 -16
- package/lib/api-routes/outbox-routes.js +7 -7
- package/lib/api-routes/pubsub-routes.js +3 -3
- package/lib/api-routes/route-helpers.js +3 -0
- package/lib/api-routes/settings-routes.js +10 -9
- package/lib/api-routes/stats-routes.js +3 -3
- package/lib/api-routes/submit-routes.js +213 -56
- package/lib/api-routes/template-routes.js +13 -13
- package/lib/api-routes/token-routes.js +15 -10
- package/lib/api-routes/webhook-route-routes.js +5 -5
- package/lib/consts.js +7 -0
- package/lib/email-client/base-client.js +230 -31
- package/lib/email-client/gmail/send-request.js +16 -1
- package/lib/email-client/gmail-client.js +89 -5
- package/lib/email-client/imap-client.js +103 -1
- package/lib/email-client/message-builder.js +24 -7
- package/lib/email-client/outlook/send-request.js +18 -1
- package/lib/email-client/outlook-client.js +79 -4
- package/lib/enum-descriptions.js +130 -0
- package/lib/imapproxy/imap-server.js +30 -26
- package/lib/imapproxy/upstream-client.js +38 -0
- package/lib/oauth2-apps.js +9 -3
- package/lib/openapi/build-document.js +318 -0
- package/lib/openapi/index.js +95 -0
- package/lib/openapi/joi-schema.js +523 -0
- package/lib/routes-ui.js +5 -1
- package/lib/schemas.js +76 -17
- package/lib/swagger-options.js +173 -0
- package/lib/tokens.js +69 -5
- package/lib/ui-routes/admin-entities-routes.js +3 -0
- package/lib/ui-routes/dashboard-routes.js +2 -26
- package/lib/ui-routes/reference-routes.js +195 -0
- package/lib/ui-routes/route-helpers.js +11 -0
- package/package.json +19 -26
- package/playwright.config.js +1 -1
- package/prepare-bundle-deps.sh +28 -0
- package/release-please-config.json +11 -0
- package/sbom.json +0 -1
- package/server.js +22 -2
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +90 -0
- package/static/js/ee-client.js +238 -8
- package/static/js/reference.js +736 -0
- package/static/js/ui.js +61 -33
- package/static/licenses.html +16 -16
- package/translations/messages.pot +13 -13
- package/views/config/ai.hbs +1 -1
- package/views/config/document-store/chat.hbs +5 -5
- package/views/config/document-store/index.hbs +2 -2
- package/views/config/document-store/pre-processing/index.hbs +1 -1
- package/views/config/email-processing.hbs +1 -1
- package/views/config/imap-proxy.hbs +1 -1
- package/views/config/license.hbs +1 -1
- package/views/config/oauth/index.hbs +3 -3
- package/views/config/security.hbs +1 -1
- package/views/config/smtp.hbs +2 -2
- package/views/dashboard.hbs +1 -1
- package/views/layout/app.hbs +18 -7
- package/views/partials/oauth_form.hbs +4 -4
- package/views/partials/reference/anchor-link.hbs +20 -0
- package/views/partials/reference/disclosure.hbs +37 -0
- package/views/partials/reference/nav.hbs +93 -0
- package/views/partials/reference/operation.hbs +127 -0
- package/views/partials/reference/params.hbs +20 -0
- package/views/partials/reference/schema-node.hbs +99 -0
- package/views/partials/reference/schema.hbs +19 -0
- package/views/partials/reference/section-heading.hbs +16 -0
- package/views/partials/reference/token-alert.hbs +24 -0
- package/views/partials/reference/try-field.hbs +31 -0
- package/views/partials/reference/try-it.hbs +78 -0
- package/views/partials/side_menu.hbs +1 -1
- package/views/partials/ui/badge.hbs +4 -2
- package/views/partials/ui/page-header.hbs +1 -1
- package/views/partials/ui/search-input.hbs +31 -0
- package/views/partials/ui/setting-ref.hbs +1 -1
- package/views/partials/ui/stat-card.hbs +4 -2
- package/views/partials/ui/tab.hbs +6 -1
- package/views/partials/ui/tabs.hbs +2 -2
- package/views/reference/index.hbs +76 -0
- package/views/reference/redirect.hbs +49 -0
- package/views/reference/tag.hbs +28 -0
- package/views/reference/token.hbs +49 -0
- package/views/tokens/index.hbs +9 -1
- package/views/webhooks/index.hbs +3 -3
- package/workers/api.js +37 -215
- package/Gruntfile.js +0 -58
- package/views/swagger/index.hbs +0 -82
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Converts joi schemas into OpenAPI 3.0 Schema Objects.
|
|
4
|
+
//
|
|
5
|
+
// This replaces the conversion half of hapi-swagger, which was archived upstream and pinned us to
|
|
6
|
+
// joi 17 because it read joi's private internals (`_flags`, `_rules`, `_ids`, `$_terms`). Everything
|
|
7
|
+
// here goes through the public `describe()` output instead, so a joi upgrade can only change what we
|
|
8
|
+
// read, never break how we read it.
|
|
9
|
+
//
|
|
10
|
+
// The output deliberately matches what hapi-swagger produced, quirks included - the generated
|
|
11
|
+
// document is a public surface (served at /swagger.json, mirrored on emailengine.dev, fed to Postman
|
|
12
|
+
// and code generators), so the migration had to be a no-op for consumers. Where a quirk is preserved
|
|
13
|
+
// on purpose it is called out in a comment. test/fixtures/openapi-golden.json is the proof: it was
|
|
14
|
+
// recorded from hapi-swagger's output before this module existed, and the switch moved exactly two
|
|
15
|
+
// things in it, both because hapi-swagger read joi's private internals and this does not:
|
|
16
|
+
// - structurally identical schemas sharing a label are now one definition instead of two;
|
|
17
|
+
// - one route's query parameters follow joi's validation order rather than declaration order,
|
|
18
|
+
// because a key with a `.when()` moves to the end of what describe() reports.
|
|
19
|
+
//
|
|
20
|
+
// Two conventions from that document are load-bearing rather than cosmetic:
|
|
21
|
+
// - `.label()` decides a schema's name under components/schemas, and labelled schemas are emitted
|
|
22
|
+
// as a $ref instead of being inlined. Renaming a label renames a public type.
|
|
23
|
+
// - The `x-constraint`, `x-format` and `x-convert` extensions carry joi rules that OpenAPI has no
|
|
24
|
+
// keyword for. lib/api-reference/format.js renders them as constraint chips.
|
|
25
|
+
|
|
26
|
+
const { isDeepStrictEqual } = require('node:util');
|
|
27
|
+
|
|
28
|
+
const Joi = require('joi');
|
|
29
|
+
|
|
30
|
+
const SCHEMA_REF_PREFIX = '#/components/schemas/';
|
|
31
|
+
|
|
32
|
+
// joi type to the OpenAPI type it starts out as. `alternatives` is not an OpenAPI type; it is a
|
|
33
|
+
// marker that gets replaced by `anyOf` once the branches are known.
|
|
34
|
+
//
|
|
35
|
+
// A joi date accepts an ISO string, a timestamp or a Date, so `date-time` describes it and the plain
|
|
36
|
+
// OpenAPI `date` (a bare YYYY-MM-DD) does not. Every date EmailEngine returns is a full timestamp.
|
|
37
|
+
const TYPE_MAP = {
|
|
38
|
+
boolean: { type: 'boolean' },
|
|
39
|
+
binary: { type: 'string', format: 'binary' },
|
|
40
|
+
date: { type: 'string', format: 'date-time' },
|
|
41
|
+
number: { type: 'number' },
|
|
42
|
+
string: { type: 'string' },
|
|
43
|
+
any: { type: 'string' },
|
|
44
|
+
array: { type: 'array' },
|
|
45
|
+
function: { type: 'string' },
|
|
46
|
+
object: { type: 'object' },
|
|
47
|
+
alternatives: { type: 'alternatives' }
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// joi rules that have no OpenAPI keyword, grouped into the extension that carries them. Order
|
|
51
|
+
// matters: it is the key order inside the emitted extension object.
|
|
52
|
+
const STRING_CONSTRAINT_RULES = ['insensitive', 'length'];
|
|
53
|
+
const STRING_FORMAT_RULES = ['creditCard', 'alphanum', 'token', 'email', 'ip', 'uri', 'guid', 'hex', 'hostname', 'isoDate'];
|
|
54
|
+
const STRING_CONVERT_RULES = ['case', 'trim'];
|
|
55
|
+
const NUMBER_CONSTRAINT_RULES = ['greater', 'less', 'precision', 'multiple', 'sign'];
|
|
56
|
+
const ARRAY_CONSTRAINT_RULES = ['length', 'unique'];
|
|
57
|
+
|
|
58
|
+
function flag(description, name) {
|
|
59
|
+
return description.flags ? description.flags[name] : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Value of a `.meta({ key: value })` entry, searching from the last meta backwards, so a schema that
|
|
63
|
+
// overrides an inherited meta wins.
|
|
64
|
+
function metaValue(description, name) {
|
|
65
|
+
const metas = description.metas;
|
|
66
|
+
if (!Array.isArray(metas)) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let index = metas.length;
|
|
71
|
+
while (index--) {
|
|
72
|
+
if (metas[index][name]) {
|
|
73
|
+
return metas[index][name];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function hasKeys(description) {
|
|
81
|
+
return !!(description.keys && Object.keys(description.keys).length);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function hasRule(rules, name) {
|
|
85
|
+
return Array.isArray(rules) && rules.some(rule => rule.name === name);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Argument of a rule, searching backwards so the last occurrence wins. `key` picks a named argument
|
|
89
|
+
// (`.max(10)` describes as `{ limit: 10 }`); without it the first argument value is returned. Rules
|
|
90
|
+
// with no arguments at all report `true`, which is what the extension objects carry for flags like
|
|
91
|
+
// `trim`.
|
|
92
|
+
function ruleArg(rules, name, key) {
|
|
93
|
+
if (!Array.isArray(rules)) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let index = rules.length;
|
|
98
|
+
while (index--) {
|
|
99
|
+
if (rules[index].name === name) {
|
|
100
|
+
if (rules[index].args) {
|
|
101
|
+
return key ? rules[index].args[key] : Object.values(rules[index].args)[0];
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isPlainObject(value) {
|
|
111
|
+
return value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function isEmpty(value) {
|
|
115
|
+
return value === null || (Array.isArray(value) && !value.length) || (isPlainObject(value) && !Object.keys(value).length);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Drops keys that carry no information, so the document is not littered with `description: null` and
|
|
119
|
+
// `properties: {}`. `default` and `example` are exempt because an empty object or an explicit null is
|
|
120
|
+
// a meaningful value for them.
|
|
121
|
+
function deleteEmptyProperties(obj) {
|
|
122
|
+
for (const key of Object.keys(obj)) {
|
|
123
|
+
const value = obj[key];
|
|
124
|
+
|
|
125
|
+
if (value === undefined || (!['default', 'example'].includes(key) && isEmpty(value))) {
|
|
126
|
+
delete obj[key];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return obj;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// joi's describe() renders a pattern as `/source/flags` because it stringifies the RegExp. OpenAPI
|
|
134
|
+
// wants the bare source, so the delimiters are peeled back off. The greedy match takes the LAST
|
|
135
|
+
// slash as the closing delimiter, which is correct because a joi pattern is always a real RegExp and
|
|
136
|
+
// flags are always trailing lowercase letters.
|
|
137
|
+
function regexSource(value) {
|
|
138
|
+
const match = /^\/(.*)\/[a-z]*$/s.exec(String(value));
|
|
139
|
+
|
|
140
|
+
return match ? match[1] : String(value);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
class SchemaConverter {
|
|
144
|
+
constructor() {
|
|
145
|
+
// Named schemas, keyed by the name a $ref points at
|
|
146
|
+
this.definitions = {};
|
|
147
|
+
|
|
148
|
+
// Highest numeric suffix handed out per base name, so allocating the next one does not scan
|
|
149
|
+
// the whole collection
|
|
150
|
+
this.suffixes = new Map();
|
|
151
|
+
|
|
152
|
+
// describe() validates its own output as it walks, which is most of the cost of a build, and
|
|
153
|
+
// the shared schemas in lib/schemas.js (every error response, every account id) are reached
|
|
154
|
+
// from most of the 82 operations. Keyed by joi schema, which is immutable, and held on the
|
|
155
|
+
// converter so it is released with it.
|
|
156
|
+
this.descriptions = new WeakMap();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
describe(schema) {
|
|
160
|
+
if (!this.descriptions.has(schema)) {
|
|
161
|
+
this.descriptions.set(schema, schema.describe());
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return this.descriptions.get(schema);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Converts a joi schema into an OpenAPI Schema Object.
|
|
169
|
+
*
|
|
170
|
+
* @param {Object} schema - a joi schema, or the describe() result of one
|
|
171
|
+
* @param {Object} [context]
|
|
172
|
+
* @param {String} [context.parameterType=body] - where the schema is used ('body', 'path', 'query', 'header')
|
|
173
|
+
* @param {Boolean} [context.useDefinitions=true] - register named schemas and emit a $ref to them
|
|
174
|
+
* @returns {Object|undefined} the schema object, or undefined when the schema is not documented
|
|
175
|
+
*/
|
|
176
|
+
convert(schema, context) {
|
|
177
|
+
const description = Joi.isSchema(schema) ? this.describe(schema) : schema;
|
|
178
|
+
|
|
179
|
+
return this.parseProperty(null, description, null, Object.assign({ parameterType: 'body', useDefinitions: true }, context));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
parseProperty(name, description, parent, context) {
|
|
183
|
+
if (!description) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A forbidden key exists only to be rejected, and swaggerHidden is how a schema opts out of
|
|
188
|
+
// the public document (deprecated Document Store fields use it). Both must not appear.
|
|
189
|
+
if (flag(description, 'presence') === 'forbidden' || metaValue(description, 'swaggerHidden') === true) {
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Path parameters are named by the path template, so a label must not rename them
|
|
194
|
+
if (!name && context.parameterType !== 'path') {
|
|
195
|
+
name = flag(description, 'label') || name;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const mapped = TYPE_MAP[description.type] || TYPE_MAP.any;
|
|
199
|
+
|
|
200
|
+
let property = { type: mapped.type };
|
|
201
|
+
if (mapped.format) {
|
|
202
|
+
property.format = mapped.format;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Presence lives on the child but is expressed on the parent's `required` array, so it has to
|
|
206
|
+
// be recorded before the child's own parsing starts
|
|
207
|
+
this.setRequiredOnParent(name, parent, description);
|
|
208
|
+
|
|
209
|
+
property = this.parseMetadata(property, description);
|
|
210
|
+
property = this.parseEnum(property, description);
|
|
211
|
+
|
|
212
|
+
if (property.type === 'string') {
|
|
213
|
+
property = this.parseString(property, description);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (property.type === 'number') {
|
|
217
|
+
property = this.parseNumber(property, description);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (description.type === 'date') {
|
|
221
|
+
property = this.parseDate(property, description);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (property.type === 'object') {
|
|
225
|
+
// An object with neither keys nor a description says nothing about its own shape, so it is
|
|
226
|
+
// published as a bare `{ type: 'object' }` - the example or default it may carry would
|
|
227
|
+
// describe a structure the document does not otherwise mention
|
|
228
|
+
property =
|
|
229
|
+
hasKeys(description) || flag(description, 'description')
|
|
230
|
+
? this.parseObject(property, description, context)
|
|
231
|
+
: { type: 'object', properties: {} };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (property.type === 'array') {
|
|
235
|
+
property = this.parseArray(property, description, context);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (property.type === 'alternatives') {
|
|
239
|
+
property = this.parseAlternatives(property, description, name, context);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// A named schema is registered once and referenced everywhere it is used. Scalars are inlined,
|
|
243
|
+
// except for a set of allowed strings: that is worth a schema of its own so every operation
|
|
244
|
+
// accepting it points at the same list. A numeric `enum` is not the same thing - it comes from
|
|
245
|
+
// `.allow(false)` on a number, which is a sentinel value rather than a named vocabulary.
|
|
246
|
+
if (context.useDefinitions && (['object', 'array'].includes(property.type) || (property.type === 'string' && property.enum))) {
|
|
247
|
+
return { $ref: SCHEMA_REF_PREFIX + this.append(name, deleteEmptyProperties(property)) };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return deleteEmptyProperties(property);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Records the child's name in the parent's `required` array. A `.when()` branch that makes the
|
|
254
|
+
// key required counts as required, because OpenAPI cannot express the condition itself - the
|
|
255
|
+
// alternative would be documenting a required field as optional.
|
|
256
|
+
setRequiredOnParent(name, parent, description) {
|
|
257
|
+
if (!parent || !name) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// NOT named `require`: shadowing it is legal and runs fine under Node, but pkg walks
|
|
262
|
+
// this file's AST looking for module requires and dies on the argument-less calls
|
|
263
|
+
// ("Cannot read properties of undefined (reading 'tokens')"), taking every binary
|
|
264
|
+
// build down with it. Nothing in the test suite can catch that - only a pkg build can.
|
|
265
|
+
const markRequired = () => {
|
|
266
|
+
if (!parent.required) {
|
|
267
|
+
parent.required = [];
|
|
268
|
+
}
|
|
269
|
+
if (!parent.required.includes(name)) {
|
|
270
|
+
parent.required.push(name);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
if (flag(description, 'presence') === 'required') {
|
|
275
|
+
markRequired();
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
for (const when of description.whens || []) {
|
|
279
|
+
if (when.then && when.then.flags && when.then.flags.presence === 'required') {
|
|
280
|
+
markRequired();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
parseMetadata(property, description) {
|
|
286
|
+
property.description = flag(description, 'description');
|
|
287
|
+
|
|
288
|
+
property.example = Array.isArray(description.examples) ? description.examples[0] : undefined;
|
|
289
|
+
|
|
290
|
+
// Everything a schema was tagged with is published as-is, minus the keys that steer
|
|
291
|
+
// generation rather than describe the value. This is how `.meta({ enumDescriptions })`
|
|
292
|
+
// reaches the API reference.
|
|
293
|
+
const published = Object.assign({}, ...(description.metas || []));
|
|
294
|
+
delete published.swaggerHidden;
|
|
295
|
+
|
|
296
|
+
if (Object.keys(published).length) {
|
|
297
|
+
property['x-meta'] = published;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
let defaultValue = flag(description, 'default');
|
|
301
|
+
if (typeof defaultValue === 'function') {
|
|
302
|
+
defaultValue = defaultValue();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// An empty array default says nothing beyond what `type: array` already says
|
|
306
|
+
if (!(property.type === 'array' && Array.isArray(defaultValue) && !defaultValue.length)) {
|
|
307
|
+
property.default = defaultValue;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return property;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Allowed values become an enum. This covers `.valid()` and `.allow()` alike, matching how the
|
|
314
|
+
// document has always been generated: `.allow('')` adds no enum (the empty string is dropped),
|
|
315
|
+
// while `.allow(null)` marks the schema nullable.
|
|
316
|
+
parseEnum(property, description) {
|
|
317
|
+
if (!Array.isArray(description.allow) || !description.allow.length) {
|
|
318
|
+
return property;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
let allowed = description.allow;
|
|
322
|
+
|
|
323
|
+
// `.valid()` prefixes the list with an override marker that is not a value
|
|
324
|
+
if (isPlainObject(allowed[0]) && allowed[0].override === true && Object.keys(allowed[0]).length === 1) {
|
|
325
|
+
allowed = allowed.slice(1);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const values = allowed.filter(value => value !== '' && value !== null);
|
|
329
|
+
if (values.length) {
|
|
330
|
+
property.enum = values;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (allowed.includes(null)) {
|
|
334
|
+
property.nullable = true;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return property;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
parseString(property, description) {
|
|
341
|
+
// Dates share the string branch but carry min/max as date bounds, not string lengths
|
|
342
|
+
if (description.type !== 'date') {
|
|
343
|
+
property.minLength = ruleArg(description.rules, 'min', 'limit');
|
|
344
|
+
property.maxLength = ruleArg(description.rules, 'max', 'limit');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const pattern = ruleArg(description.rules, 'pattern', 'regex');
|
|
348
|
+
if (pattern) {
|
|
349
|
+
property.pattern = regexSource(pattern);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
this.convertRules(property, description.rules, STRING_CONSTRAINT_RULES, 'x-constraint');
|
|
353
|
+
this.convertRules(property, description.rules, STRING_FORMAT_RULES, 'x-format');
|
|
354
|
+
this.convertRules(property, description.rules, STRING_CONVERT_RULES, 'x-convert');
|
|
355
|
+
|
|
356
|
+
return property;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
parseNumber(property, description) {
|
|
360
|
+
property.minimum = ruleArg(description.rules, 'min');
|
|
361
|
+
property.maximum = ruleArg(description.rules, 'max');
|
|
362
|
+
|
|
363
|
+
if (hasRule(description.rules, 'integer')) {
|
|
364
|
+
property.type = 'integer';
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const format = metaValue(description, 'format');
|
|
368
|
+
if (typeof format === 'string') {
|
|
369
|
+
property.format = format;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
this.convertRules(property, description.rules, NUMBER_CONSTRAINT_RULES, 'x-constraint');
|
|
373
|
+
|
|
374
|
+
return property;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// A date expressed as a number of milliseconds or seconds is not a string at all
|
|
378
|
+
parseDate(property, description) {
|
|
379
|
+
if (['timestamp', 'javascript', 'unix'].includes(flag(description, 'format'))) {
|
|
380
|
+
property.type = 'integer';
|
|
381
|
+
delete property.format;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return property;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
parseObject(property, description, context) {
|
|
388
|
+
property.properties = {};
|
|
389
|
+
|
|
390
|
+
for (const key of Object.keys(description.keys || {})) {
|
|
391
|
+
const child = description.keys[key];
|
|
392
|
+
|
|
393
|
+
// A labelled child is registered under its label but still keyed by its property name
|
|
394
|
+
const childName = flag(child, 'label') || key;
|
|
395
|
+
|
|
396
|
+
const parsed = this.parseProperty(childName, child, property, context);
|
|
397
|
+
if (parsed) {
|
|
398
|
+
property.properties[key] = parsed;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// The label was used for the definition name; the parent's required list has to name the
|
|
402
|
+
// property, not the type
|
|
403
|
+
if (childName !== key && property.required) {
|
|
404
|
+
const index = property.required.indexOf(childName);
|
|
405
|
+
if (index !== -1) {
|
|
406
|
+
property.required[index] = key;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return property;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
parseArray(property, description, context) {
|
|
415
|
+
property.minItems = ruleArg(description.rules, 'min');
|
|
416
|
+
property.maxItems = ruleArg(description.rules, 'max');
|
|
417
|
+
|
|
418
|
+
this.convertRules(property, description.rules, ARRAY_CONSTRAINT_RULES, 'x-constraint');
|
|
419
|
+
|
|
420
|
+
// `.single()` accepts a bare value where a list is expected. OpenAPI has no way to say that,
|
|
421
|
+
// and it is a real difference for a caller writing a request by hand.
|
|
422
|
+
if (flag(description, 'sparse')) {
|
|
423
|
+
this.addExtension(property, 'x-constraint', 'sparse', true);
|
|
424
|
+
}
|
|
425
|
+
if (flag(description, 'single')) {
|
|
426
|
+
this.addExtension(property, 'x-constraint', 'single', true);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Item schemas take no parent: an item's own presence flag has nowhere to go, since `required`
|
|
430
|
+
// names an object's keys and an array has none
|
|
431
|
+
const items = (description.items || []).map(item => this.parseProperty(flag(item, 'label'), item, null, context));
|
|
432
|
+
|
|
433
|
+
if (items.length > 1) {
|
|
434
|
+
property.items = { anyOf: items };
|
|
435
|
+
} else {
|
|
436
|
+
property.items = items[0] || { type: 'string' };
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return property;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// `Joi.alternatives().try(a, b)` and a conditional `.when()` both collapse into `anyOf`. The
|
|
443
|
+
// condition itself is dropped: OpenAPI has no way to say "this shape when that field is set".
|
|
444
|
+
parseAlternatives(property, description, name, context) {
|
|
445
|
+
const matches = description.matches || [];
|
|
446
|
+
|
|
447
|
+
const branches =
|
|
448
|
+
matches[0] && matches[0].schema ? matches.map(match => match.schema) : matches.flatMap(match => [match.then, match.otherwise].filter(Boolean));
|
|
449
|
+
|
|
450
|
+
// No parent, for the same reason as array items: a branch has no key to be required under
|
|
451
|
+
property.anyOf = branches.map(branch => this.parseProperty(flag(branch, 'label') || name, branch, null, context)).filter(Boolean);
|
|
452
|
+
|
|
453
|
+
delete property.type;
|
|
454
|
+
|
|
455
|
+
return property;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
convertRules(property, rules, ruleNames, groupName) {
|
|
459
|
+
for (const ruleName of ruleNames) {
|
|
460
|
+
if (!hasRule(rules, ruleName)) {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
let value = ruleArg(rules, ruleName);
|
|
465
|
+
if (isPlainObject(value) && !Object.keys(value).length) {
|
|
466
|
+
value = undefined;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
this.addExtension(property, groupName, ruleName, value);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
addExtension(property, groupName, ruleName, value) {
|
|
474
|
+
if (!property[groupName]) {
|
|
475
|
+
property[groupName] = {};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
property[groupName][ruleName] = value !== undefined ? value : true;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Registers a schema under a name and returns the name to reference it by.
|
|
483
|
+
*
|
|
484
|
+
* Names come from joi labels, and two structurally different schemas can carry the same label -
|
|
485
|
+
* `AddressList` is used for four different address lists, `status` for three unrelated status
|
|
486
|
+
* enums. Those get a numeric suffix (`AddressList1`) so neither definition is lost. It is a wart:
|
|
487
|
+
* the fix is distinct labels in the schemas themselves, not a cleverer generator.
|
|
488
|
+
*
|
|
489
|
+
* Schemas that are structurally identical always share one definition, whatever joi object they
|
|
490
|
+
* were built from. Without that, the same label reached from two routes produces two identical
|
|
491
|
+
* copies, and the copies then differ only by which numbered sibling they reference.
|
|
492
|
+
*/
|
|
493
|
+
append(name, definition) {
|
|
494
|
+
const collection = this.definitions;
|
|
495
|
+
|
|
496
|
+
if (!name) {
|
|
497
|
+
name = this.nextName('Model');
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// The name itself, then the numbered siblings it has already spawned
|
|
501
|
+
for (let suffix = 0; suffix <= (this.suffixes.get(name) || 0); suffix++) {
|
|
502
|
+
const candidate = suffix ? name + suffix : name;
|
|
503
|
+
|
|
504
|
+
if (isDeepStrictEqual(collection[candidate], definition)) {
|
|
505
|
+
return encodeURIComponent(candidate);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const key = collection[name] ? this.nextName(name) : name;
|
|
510
|
+
collection[key] = definition;
|
|
511
|
+
|
|
512
|
+
return encodeURIComponent(key);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
nextName(base) {
|
|
516
|
+
const suffix = (this.suffixes.get(base) || 0) + 1;
|
|
517
|
+
this.suffixes.set(base, suffix);
|
|
518
|
+
|
|
519
|
+
return base + suffix;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
module.exports = { SchemaConverter, deleteEmptyProperties, SCHEMA_REF_PREFIX };
|
package/lib/routes-ui.js
CHANGED
|
@@ -5,6 +5,7 @@ const smtpTestRoutes = require('./ui-routes/smtp-test-routes');
|
|
|
5
5
|
const unsubscribeRoutes = require('./ui-routes/unsubscribe-routes');
|
|
6
6
|
const internalsRoutes = require('./ui-routes/internals-routes');
|
|
7
7
|
const dashboardRoutes = require('./ui-routes/dashboard-routes');
|
|
8
|
+
const referenceRoutes = require('./ui-routes/reference-routes');
|
|
8
9
|
const exportRoutes = require('./ui-routes/export-routes');
|
|
9
10
|
const networkConfigRoutes = require('./ui-routes/network-config-routes');
|
|
10
11
|
const documentStoreRoutes = require('./ui-routes/document-store-routes');
|
|
@@ -26,9 +27,12 @@ function applyRoutes(server, call) {
|
|
|
26
27
|
// System internals / threads tools routes
|
|
27
28
|
internalsRoutes({ server, call });
|
|
28
29
|
|
|
29
|
-
// Dashboard and standalone informational pages (
|
|
30
|
+
// Dashboard and standalone informational pages (legal, upgrade)
|
|
30
31
|
dashboardRoutes({ server, call });
|
|
31
32
|
|
|
33
|
+
// Server-rendered API reference, plus the /admin/swagger redirect it replaced
|
|
34
|
+
referenceRoutes({ server });
|
|
35
|
+
|
|
32
36
|
// Account data export routes
|
|
33
37
|
exportRoutes({ server });
|
|
34
38
|
|