emailengine-app 2.78.0 → 2.79.1
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/.ncurc.js +23 -13
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +68 -0
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +112 -36
- package/lib/api-reference/format.js +91 -4
- package/lib/api-reference/model.js +144 -19
- package/lib/api-reference/schema-tree.js +282 -28
- package/lib/api-routes/account-routes.js +80 -34
- package/lib/api-routes/blocklist-routes.js +21 -47
- package/lib/api-routes/chat-routes.js +10 -12
- package/lib/api-routes/delivery-test-routes.js +6 -26
- package/lib/api-routes/export-routes.js +2 -0
- package/lib/api-routes/gateway-routes.js +52 -11
- package/lib/api-routes/license-routes.js +2 -0
- package/lib/api-routes/mailbox-routes.js +29 -26
- package/lib/api-routes/message-routes.js +27 -21
- package/lib/api-routes/oauth2-app-routes.js +11 -29
- package/lib/api-routes/operation-impact.js +80 -0
- package/lib/api-routes/outbox-routes.js +15 -5
- package/lib/api-routes/permission-map.js +401 -0
- package/lib/api-routes/route-helpers.js +294 -9
- package/lib/api-routes/route-metadata.js +28 -0
- package/lib/api-routes/settings-routes.js +66 -38
- package/lib/api-routes/stats-routes.js +2 -2
- package/lib/api-routes/submit-routes.js +53 -31
- package/lib/api-routes/template-routes.js +3 -0
- package/lib/api-routes/token-routes.js +526 -72
- package/lib/api-routes/webhook-route-routes.js +14 -4
- package/lib/arf-detect.js +17 -4
- package/lib/auth-token.js +80 -8
- package/lib/bounce-detect.js +28 -17
- package/lib/consts.js +16 -0
- package/lib/db.js +26 -2
- package/lib/delivery-error.js +30 -1
- package/lib/email-client/base-client.js +27 -41
- package/lib/email-client/gmail-client.js +23 -17
- package/lib/email-client/imap/mailbox.js +58 -59
- package/lib/email-client/imap/subconnection.js +10 -7
- package/lib/email-client/imap/sync-operations.js +46 -46
- package/lib/email-client/imap-client.js +85 -28
- package/lib/email-client/message-builder.js +3 -3
- package/lib/email-client/notification-handler.js +1 -1
- package/lib/email-client/outlook/graph-api.js +10 -4
- package/lib/email-client/outlook-client.js +56 -64
- package/lib/email-client/smtp-pool-manager.js +1 -1
- package/lib/enum-descriptions.js +92 -2
- package/lib/export.js +1 -1
- package/lib/field-usage.js +133 -0
- package/lib/gateway.js +1 -1
- package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
- package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
- package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
- package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
- package/lib/imapproxy/imap-core/lib/imap-connection.js +15 -5
- package/lib/imapproxy/imap-server.js +27 -7
- package/lib/license-beacon.js +4 -9
- package/lib/lists.js +49 -1
- package/lib/llm-pre-process.js +5 -5
- package/lib/logger.js +5 -1
- package/lib/lua/h-set-new-mark.lua +36 -0
- package/lib/message-port-stream.js +84 -1
- package/lib/metrics-collector.js +2 -2
- package/lib/oauth/gmail.js +9 -12
- package/lib/oauth/mail-ru.js +5 -7
- package/lib/oauth/outlook.js +9 -9
- package/lib/oauth/pubsub/google.js +25 -10
- package/lib/oauth/scope-checker.js +1 -1
- package/lib/oauth2-apps.js +290 -292
- package/lib/openapi/build-document.js +20 -8
- package/lib/openapi/joi-schema.js +20 -0
- package/lib/outbox.js +85 -17
- package/lib/pre-process.js +8 -8
- package/lib/queue-stats.js +49 -0
- package/lib/read-env-value.js +1 -1
- package/lib/reconnection-manager.js +2 -2
- package/lib/rewrite-text-nodes.js +4 -3
- package/lib/routes-ui.js +4 -0
- package/lib/schemas.js +218 -162
- package/lib/settings.js +98 -5
- package/lib/sub-script.js +2 -1
- package/lib/swagger-options.js +2 -1
- package/lib/templates.js +4 -4
- package/lib/threads.js +2 -2
- package/lib/token-audit-log.js +231 -0
- package/lib/token-permission-view.js +219 -0
- package/lib/token-permissions.js +172 -0
- package/lib/tokens.js +247 -66
- package/lib/tools.js +142 -37
- package/lib/ui-routes/account-routes.js +42 -15
- package/lib/ui-routes/admin-config-routes.js +18 -10
- package/lib/ui-routes/admin-entities-routes.js +117 -38
- package/lib/ui-routes/auth-routes.js +30 -24
- package/lib/ui-routes/export-routes.js +10 -4
- package/lib/ui-routes/oauth-config-routes.js +12 -12
- package/lib/ui-routes/reference-routes.js +3 -3
- package/lib/ui-routes/route-helpers.js +78 -2
- package/lib/ui-routes/settings-page.js +1 -1
- package/lib/ui-routes/smtp-test-routes.js +1 -1
- package/lib/ui-routes/suppression-list-routes.js +299 -0
- package/lib/ui-routes/unsubscribe-routes.js +19 -29
- package/lib/utils/decode-headers.js +42 -0
- package/lib/utils/header-map.js +48 -0
- package/lib/utils/network.js +2 -2
- package/lib/utils/unsafe-key.js +59 -0
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-routing.js +84 -0
- package/lib/webhooks.js +48 -14
- package/package.json +11 -10
- package/sbom.json +1 -1
- package/server.js +116 -55
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +136 -9
- package/static/js/reference.js +456 -10
- package/static/js/ui.js +43 -0
- package/static/licenses.html +51 -41
- package/translations/messages.pot +59 -59
- package/views/accounts/account.hbs +75 -13
- package/views/accounts/browse.hbs +19 -36
- package/views/accounts/edit.hbs +2 -2
- package/views/config/logging.hbs +6 -0
- package/views/config/oauth/app.hbs +0 -2
- package/views/config/security.hbs +13 -0
- package/views/gateways/edit.hbs +1 -1
- package/views/gateways/gateway.hbs +2 -2
- package/views/gateways/index.hbs +7 -7
- package/views/partials/accounts_table.hbs +7 -7
- package/views/partials/oauth_form.hbs +0 -15
- package/views/partials/reference/disclosure.hbs +8 -2
- package/views/partials/reference/operation.hbs +47 -13
- package/views/partials/reference/params.hbs +17 -1
- package/views/partials/reference/schema-node.hbs +110 -52
- package/views/partials/reference/schema-tools.hbs +25 -0
- package/views/partials/reference/try-it.hbs +84 -11
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/ui/checkbox.hbs +2 -2
- package/views/partials/ui/tabs.hbs +7 -1
- package/views/reference/token.hbs +4 -0
- package/views/suppression-lists/index.hbs +85 -0
- package/views/suppression-lists/list.hbs +87 -0
- package/views/templates/index.hbs +10 -4
- package/views/templates/template.hbs +1 -1
- package/views/tokens/index.hbs +53 -6
- package/views/tokens/new.hbs +334 -5
- package/workers/api.js +185 -102
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +77 -78
- package/workers/smtp.js +13 -7
- package/workers/submit.js +40 -30
- package/workers/webhooks.js +80 -26
- package/lib/feature-flags.js +0 -48
|
@@ -108,6 +108,42 @@ function rangeChip(min, max, unit) {
|
|
|
108
108
|
return null;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
// Length limits at or above this read better as a size than as a character count. `max
|
|
112
|
+
// 5242880 chars` is a number nobody holds; `max 5 MB` is the same fact in a form a reader
|
|
113
|
+
// can act on. Below it the exact count is the more useful answer - a 1024 character limit
|
|
114
|
+
// on a preview line is about the text, not about bytes.
|
|
115
|
+
const SIZE_CHIP_MIN = 8192;
|
|
116
|
+
|
|
117
|
+
// Size label for a character limit, or null when the limit is not a round size. Only exact
|
|
118
|
+
// multiples of 1024 convert: rounding 2560 to "2.5 KB" or, worse, "3 KB" would state a
|
|
119
|
+
// limit the API does not have, and the exact number is the honest answer there.
|
|
120
|
+
function sizeLabel(value) {
|
|
121
|
+
if (typeof value !== 'number' || value < SIZE_CHIP_MIN || value % 1024) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const mb = value / (1024 * 1024);
|
|
126
|
+
if (Number.isInteger(mb)) {
|
|
127
|
+
return `${mb} MB`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return `${value / 1024} KB`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The string-length chip. A limit large enough to be a size is rendered as one, but only
|
|
134
|
+
// when there is no minimum to state alongside it - "1 to 5 MB" would be mixing a character
|
|
135
|
+
// count with a byte size in one phrase. No schema in the current document has both.
|
|
136
|
+
function lengthChip(min, max) {
|
|
137
|
+
if (typeof min !== 'number') {
|
|
138
|
+
const size = sizeLabel(max);
|
|
139
|
+
if (size) {
|
|
140
|
+
return `max ${size}`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return rangeChip(min, max, 'chars');
|
|
145
|
+
}
|
|
146
|
+
|
|
111
147
|
// Short constraint chips shown next to a property. Covers both the standard OpenAPI
|
|
112
148
|
// keywords and the `x-*` extensions the generator emits for joi rules OpenAPI has no
|
|
113
149
|
// keyword for (accepted URI schemes, email format, value coercion) - real validation
|
|
@@ -125,7 +161,7 @@ function constraintList(schema) {
|
|
|
125
161
|
|
|
126
162
|
for (const chip of [
|
|
127
163
|
rangeChip(schema.minimum, schema.maximum, ''),
|
|
128
|
-
|
|
164
|
+
lengthChip(schema.minLength, schema.maxLength),
|
|
129
165
|
rangeChip(schema.minItems, schema.maxItems, 'items')
|
|
130
166
|
]) {
|
|
131
167
|
if (chip) {
|
|
@@ -149,11 +185,13 @@ function constraintList(schema) {
|
|
|
149
185
|
}
|
|
150
186
|
}
|
|
151
187
|
|
|
188
|
+
// `trimmed` is deliberately not a chip. joi trims 162 strings in the document, so it was
|
|
189
|
+
// the most common chip on the page and it never changed what anyone sent: leading
|
|
190
|
+
// whitespace on an account id is not a thing callers do on purpose, and being told it
|
|
191
|
+
// would be removed answered a question nobody had. Case coercion stays, because that one
|
|
192
|
+
// does change the value you get back.
|
|
152
193
|
const xConvert = schema['x-convert'];
|
|
153
194
|
if (xConvert && typeof xConvert === 'object') {
|
|
154
|
-
if (xConvert.trim) {
|
|
155
|
-
chips.push('trimmed');
|
|
156
|
-
}
|
|
157
195
|
if (xConvert.case === 'lower') {
|
|
158
196
|
chips.push('lowercased');
|
|
159
197
|
}
|
|
@@ -169,6 +207,54 @@ function constraintList(schema) {
|
|
|
169
207
|
return chips;
|
|
170
208
|
}
|
|
171
209
|
|
|
210
|
+
// How much of an example value a property row shows before it is cut.
|
|
211
|
+
//
|
|
212
|
+
// The value rides the end of the description rather than taking a line of its own, which
|
|
213
|
+
// only works while it is short enough to share one. The prose column is 34rem, about 86
|
|
214
|
+
// characters; the median example in the document is 15 characters and the 90th percentile
|
|
215
|
+
// is 33, so this cap trips on 67 rows out of 1,056 - base64 blobs, embedded JSON and long
|
|
216
|
+
// URLs, where the opening characters already show the shape. The full value stays reachable
|
|
217
|
+
// through the title attribute, and through data-example for the try-it autocompleter.
|
|
218
|
+
const EXAMPLE_MAX_CHARS = 40;
|
|
219
|
+
|
|
220
|
+
// One example value, formatted for a property row, or null when the value would say nothing.
|
|
221
|
+
//
|
|
222
|
+
// Everything is rendered as JSON, including strings, so the row shows what you would paste
|
|
223
|
+
// rather than prose that happens to sit where prose already is. A cut string is closed off
|
|
224
|
+
// again rather than sliced mid-literal, so the row never shows a dangling quote.
|
|
225
|
+
//
|
|
226
|
+
// A cut value comes back with two more fields, because the two things that want the whole
|
|
227
|
+
// value want it in different forms. `title` is the native tooltip and is the raw value, with
|
|
228
|
+
// no quotes around it. `full` is the JSON form, which is what the try-it autocompleter
|
|
229
|
+
// inserts - handing it `title` instead produced `"raw": TUlNRS1WZXJ...`, an unquoted string
|
|
230
|
+
// in a JSON body. Both are null when nothing was cut, and the row emits neither.
|
|
231
|
+
function formatExample(value) {
|
|
232
|
+
if (typeof value === 'string') {
|
|
233
|
+
// A multi-line example (an HTML body, a PEM key) would break the row it rides on
|
|
234
|
+
const flat = value.replace(/\s+/g, ' ').trim();
|
|
235
|
+
if (!flat) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (flat.length <= EXAMPLE_MAX_CHARS) {
|
|
240
|
+
return { text: JSON.stringify(flat), title: null, full: null };
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return { text: JSON.stringify(`${flat.slice(0, EXAMPLE_MAX_CHARS)}...`), title: value, full: JSON.stringify(flat) };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Everything else is a number or a flat array of scalars - rowExample() has already
|
|
247
|
+
// rejected the values JSON.stringify has trouble with - so this cuts the rendered form
|
|
248
|
+
// rather than the value, which is why it does not close anything back off.
|
|
249
|
+
const text = JSON.stringify(value);
|
|
250
|
+
|
|
251
|
+
if (text.length <= EXAMPLE_MAX_CHARS) {
|
|
252
|
+
return { text, title: null, full: null };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return { text: `${text.slice(0, EXAMPLE_MAX_CHARS)}...`, title: text, full: text };
|
|
256
|
+
}
|
|
257
|
+
|
|
172
258
|
// JSON rendered for the example panels. Kept here so the pretty-printing is identical
|
|
173
259
|
// everywhere (page body, code samples, try-it request editor).
|
|
174
260
|
function stringifyExample(value) {
|
|
@@ -189,5 +275,6 @@ module.exports = {
|
|
|
189
275
|
operationUrl,
|
|
190
276
|
methodVariant,
|
|
191
277
|
constraintList,
|
|
278
|
+
formatExample,
|
|
192
279
|
stringifyExample
|
|
193
280
|
};
|
|
@@ -7,14 +7,65 @@
|
|
|
7
7
|
// base URL used in the code samples) is applied later, in lib/api-reference/index.js.
|
|
8
8
|
|
|
9
9
|
const { formatDescription, slugify, tagUrl, operationUrl, methodVariant, constraintList, stringifyExample } = require('./format');
|
|
10
|
-
const { buildSchemaTree, buildExample, typeLabel, enumInfo, requiredFirst } = require('./schema-tree');
|
|
10
|
+
const { buildSchemaTree, buildExample, typeLabel, enumInfo, requiredFirst, rowExample, itemExampleFor } = require('./schema-tree');
|
|
11
11
|
const { readCodeSamples } = require('./code-samples');
|
|
12
12
|
const { NOTES_SEPARATOR } = require('../openapi');
|
|
13
|
+
const { IMPACT, resolveImpact } = require('../api-routes/operation-impact');
|
|
13
14
|
|
|
14
15
|
const METHOD_ORDER = ['get', 'post', 'put', 'patch', 'delete', 'options', 'head'];
|
|
15
16
|
|
|
16
17
|
const JSON_CONTENT_TYPE = 'application/json';
|
|
17
18
|
|
|
19
|
+
// What the Try it panel says before you press Send, keyed on the operation's resolved impact.
|
|
20
|
+
// The resolution - declared `x-ee-impact` if there is one, otherwise the HTTP method default -
|
|
21
|
+
// belongs to lib/api-routes/operation-impact.js, because the token permission model narrows on
|
|
22
|
+
// the same value. Deriving the method default here as well is how a route ends up classified one
|
|
23
|
+
// way for this banner and another way for access control.
|
|
24
|
+
//
|
|
25
|
+
// Every panel used to carry the same warning - "requests run against this instance with real
|
|
26
|
+
// data" - on all 82 operations, 42 of which only read. A warning that fires on GET /v1/stats
|
|
27
|
+
// is how a reader learns to skim past the one on DELETE /v1/account/{account}, and it
|
|
28
|
+
// described the mechanism (this is a real POST) rather than the consequence. Weight now
|
|
29
|
+
// tracks consequence: nothing on a read, one muted line on an ordinary write, a real warning
|
|
30
|
+
// where the effect cannot be taken back.
|
|
31
|
+
// `warn` picks the rendering in reference/try-it: an alert box when true, one muted line
|
|
32
|
+
// otherwise. A boolean rather than a level string because the template can branch on it with
|
|
33
|
+
// a plain {{#if}}, and this codebase has no comparison helper to test a string against.
|
|
34
|
+
// `confirm` puts a confirmation step in front of Send, on the operations whose effect cannot
|
|
35
|
+
// be taken back. Every field arrives prefilled from the schema example, so
|
|
36
|
+
// DELETE /v1/account/{account} sits one click from a real deletion with nothing in between.
|
|
37
|
+
//
|
|
38
|
+
// Sending is behind the same dialog, and the draft submit is the reason. Its body is
|
|
39
|
+
// entirely optional overrides - the stored draft already carries its own recipients, and
|
|
40
|
+
// lib/api-routes/submit-routes.js says as much - so Send there mails people the reader never
|
|
41
|
+
// typed and cannot see anywhere in the panel. Handing that a lighter treatment than a DELETE
|
|
42
|
+
// would have the guard weakest exactly where the request says least about itself.
|
|
43
|
+
//
|
|
44
|
+
// The dialog shows the resolved request, method and path with the values actually in the
|
|
45
|
+
// form, plus the body when there is one: "delete this account?" is a weaker question than
|
|
46
|
+
// "DELETE /v1/account/user123?".
|
|
47
|
+
const TRY_IMPACT = {
|
|
48
|
+
[IMPACT.DESTRUCTIVE]: { warn: true, confirm: true, text: 'This permanently removes data from this instance. It cannot be undone from here.' },
|
|
49
|
+
[IMPACT.SENDS]: { warn: true, confirm: true, text: 'This sends real email. Messages reach the recipients in the request, not a sandbox.' },
|
|
50
|
+
[IMPACT.READONLY]: null, // reads only, so the panel says nothing at all
|
|
51
|
+
[IMPACT.WRITE]: { warn: false, text: 'Runs against live data on this instance.' }
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
function tryImpact(operation, method) {
|
|
55
|
+
// An unresolvable impact lands on the same `null` as READONLY, which is safe only because a
|
|
56
|
+
// route cannot declare a bad impact and reach a release: test/api-reference-test.js asserts
|
|
57
|
+
// every declaration against DECLARABLE_IMPACTS.
|
|
58
|
+
return TRY_IMPACT[resolveImpact(operation['x-ee-impact'], method)] || null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// A parameter group this long, whose members are all the same type and carry no
|
|
62
|
+
// documentation of their own, is one decision rather than N of them. GET /v1/settings takes
|
|
63
|
+
// 87 boolean query parameters that select which settings come back; rendered a row each they
|
|
64
|
+
// were roughly 260 lines of page at the same visual weight as parameters that carry a real
|
|
65
|
+
// choice, and they pushed the response schema three screens down. Matched on shape rather
|
|
66
|
+
// than on the endpoint, so anything similar added later is covered too.
|
|
67
|
+
const FLAG_GROUP_MIN = 12;
|
|
68
|
+
|
|
18
69
|
function statusVariant(code) {
|
|
19
70
|
const numeric = Number(code);
|
|
20
71
|
if (numeric >= 200 && numeric < 300) {
|
|
@@ -48,6 +99,7 @@ function pickContent(content) {
|
|
|
48
99
|
|
|
49
100
|
function buildParameter(spec, parameter, operationId) {
|
|
50
101
|
const schema = parameter.schema || {};
|
|
102
|
+
const enums = enumInfo(schema);
|
|
51
103
|
|
|
52
104
|
const view = {
|
|
53
105
|
name: parameter.name,
|
|
@@ -56,17 +108,25 @@ function buildParameter(spec, parameter, operationId) {
|
|
|
56
108
|
required: !!parameter.required,
|
|
57
109
|
typeLabel: typeLabel(spec, schema),
|
|
58
110
|
descriptionHtml: formatDescription(parameter.description || schema.description),
|
|
111
|
+
usageHtml: formatDescription(schema['x-meta'] && schema['x-meta'].usage),
|
|
59
112
|
constraints: constraintList(schema),
|
|
60
113
|
deprecated: !!parameter.deprecated,
|
|
114
|
+
// Shown on the row, under the same rules a schema property gets. A parameter is
|
|
115
|
+
// built with a tree node's field names on purpose - reference/params renders it
|
|
116
|
+
// through reference/schema-node - so the example belongs here too. Nothing
|
|
117
|
+
// inherits: a parameter has no ancestor to inherit from.
|
|
118
|
+
example: rowExample(schema, { itemExample: itemExampleFor(spec, schema, []), enums }),
|
|
61
119
|
// Booleans and enums render as a select in the try-it form, not a text field
|
|
62
120
|
isBoolean: schema.type === 'boolean'
|
|
63
121
|
};
|
|
64
122
|
|
|
65
|
-
|
|
66
|
-
if (enums) {
|
|
123
|
+
if (enums && enums.values.length) {
|
|
67
124
|
view.enumValues = enums.values;
|
|
68
125
|
view.enumDocumented = enums.documented;
|
|
69
126
|
}
|
|
127
|
+
if (enums && enums.alsoAccepts.length) {
|
|
128
|
+
view.alsoAccepts = enums.alsoAccepts;
|
|
129
|
+
}
|
|
70
130
|
|
|
71
131
|
if (typeof schema.default !== 'undefined') {
|
|
72
132
|
view.defaultValue = typeof schema.default === 'string' ? schema.default : JSON.stringify(schema.default);
|
|
@@ -88,6 +148,32 @@ function buildParameter(spec, parameter, operationId) {
|
|
|
88
148
|
return view;
|
|
89
149
|
}
|
|
90
150
|
|
|
151
|
+
// Names of a parameter group that is a flag list rather than N documented parameters, or
|
|
152
|
+
// null when the group is anything else. See FLAG_GROUP_MIN.
|
|
153
|
+
//
|
|
154
|
+
// The boolean and default-false tests are not incidental: reference/params renders the group
|
|
155
|
+
// under a fixed sentence telling the reader to set the ones they want to `true`. A predicate
|
|
156
|
+
// looser than that sentence would eventually match a group of undocumented strings and
|
|
157
|
+
// describe it wrongly, having also dropped each member's type, default and anchor. Predicate
|
|
158
|
+
// and prose have to mean the same thing.
|
|
159
|
+
function flagNames(parameters) {
|
|
160
|
+
if (parameters.length < FLAG_GROUP_MIN) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const uniform = parameters.every(
|
|
165
|
+
parameter =>
|
|
166
|
+
parameter.typeLabel === 'boolean' &&
|
|
167
|
+
parameter.defaultValue === 'false' &&
|
|
168
|
+
!parameter.descriptionHtml &&
|
|
169
|
+
!parameter.required &&
|
|
170
|
+
!parameter.deprecated &&
|
|
171
|
+
!parameter.enumValues
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
return uniform ? parameters.map(parameter => parameter.name) : null;
|
|
175
|
+
}
|
|
176
|
+
|
|
91
177
|
function buildBody(spec, requestBody, operationId) {
|
|
92
178
|
if (!requestBody) {
|
|
93
179
|
return null;
|
|
@@ -99,14 +185,39 @@ function buildBody(spec, requestBody, operationId) {
|
|
|
99
185
|
}
|
|
100
186
|
|
|
101
187
|
const schema = picked.media.schema;
|
|
102
|
-
|
|
188
|
+
// Whether the route declared the whole payload itself, in which case neither view is
|
|
189
|
+
// synthesized and there is nothing to offer a second tab for
|
|
190
|
+
const curated = typeof picked.media.example !== 'undefined';
|
|
191
|
+
const exampleValue = curated ? picked.media.example : buildExample(spec, schema);
|
|
192
|
+
const tree = buildSchemaTree(spec, schema, `${operationId}.body`);
|
|
193
|
+
|
|
194
|
+
// The curated payload answers "what does a normal call look like" and is the right
|
|
195
|
+
// default. It cannot also answer "what else can I send", because an object-level
|
|
196
|
+
// `.example()` stops the descent, so every key its author left out is invisible: 10 of
|
|
197
|
+
// 71 fields on POST /v1/account/{account}/submit, 8 of 62 on PUT /v1/account/{account},
|
|
198
|
+
// 466 of 651 across all request bodies. The complete view fills the rest in from the
|
|
199
|
+
// per-property examples, curated values still winning wherever they exist.
|
|
200
|
+
//
|
|
201
|
+
// Only offered when it actually differs, which is 8 bodies of the document's 34 - on the
|
|
202
|
+
// rest the typical payload already names every field and a second identical tab would be
|
|
203
|
+
// a control that does nothing.
|
|
204
|
+
const completeValue = curated ? undefined : buildExample(spec, schema, { complete: true });
|
|
205
|
+
const exampleJson = stringifyExample(exampleValue);
|
|
206
|
+
const completeJson = stringifyExample(completeValue);
|
|
103
207
|
|
|
104
208
|
return {
|
|
105
209
|
contentType: picked.contentType,
|
|
106
210
|
descriptionHtml: formatDescription(requestBody.description),
|
|
107
|
-
tree
|
|
211
|
+
tree,
|
|
212
|
+
scopeId: `${operationId}-body-schema`,
|
|
108
213
|
exampleValue,
|
|
109
|
-
exampleJson
|
|
214
|
+
exampleJson,
|
|
215
|
+
completeJson: completeJson !== exampleJson ? completeJson : '',
|
|
216
|
+
// Panel ids for the two views. Built here for the same reason the response tab ids
|
|
217
|
+
// are: ui/tabs neutralizes its own hash params inside the partial block, which puts
|
|
218
|
+
// the operation id out of reach for composing them there.
|
|
219
|
+
exampleTabId: `${operationId}-body-example`,
|
|
220
|
+
completeTabId: `${operationId}-body-example-full`
|
|
110
221
|
};
|
|
111
222
|
}
|
|
112
223
|
|
|
@@ -125,18 +236,21 @@ function buildResponses(spec, responses, operationId) {
|
|
|
125
236
|
const schema = picked && picked.media.schema;
|
|
126
237
|
const exampleValue = picked && typeof picked.media.example !== 'undefined' ? picked.media.example : buildExample(spec, schema);
|
|
127
238
|
|
|
239
|
+
// Property trees are built for success responses only. The document has 474
|
|
240
|
+
// non-2xx responses sharing 8 distinct shapes - all variations on the
|
|
241
|
+
// {statusCode, error, message} envelope - so expanding them per operation
|
|
242
|
+
// added 2,400 of a tag page's 4,400 tree nodes and a quarter of its bytes to
|
|
243
|
+
// restate the same thing. The error envelope is documented once on the
|
|
244
|
+
// landing page, and each response still carries its own example.
|
|
245
|
+
const tree = schema && variant === 'success' ? buildSchemaTree(spec, schema, `${operationId}.resp.${code}`) : null;
|
|
246
|
+
|
|
128
247
|
return {
|
|
129
248
|
code,
|
|
130
249
|
variant,
|
|
131
250
|
descriptionHtml: formatDescription(response.description),
|
|
132
251
|
contentType: picked ? picked.contentType : null,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// {statusCode, error, message} envelope - so expanding them per operation
|
|
136
|
-
// added 2,400 of a tag page's 4,400 tree nodes and a quarter of its bytes to
|
|
137
|
-
// restate the same thing. The error envelope is documented once on the
|
|
138
|
-
// landing page, and each response still carries its own example.
|
|
139
|
-
tree: schema && variant === 'success' ? buildSchemaTree(spec, schema, `${operationId}.resp.${code}`) : null,
|
|
252
|
+
tree,
|
|
253
|
+
scopeId: `${operationId}-resp-${code}-schema`,
|
|
140
254
|
exampleJson: schema ? stringifyExample(exampleValue) : ''
|
|
141
255
|
};
|
|
142
256
|
});
|
|
@@ -156,6 +270,13 @@ function buildOperation(spec, path, method, operation, tagName) {
|
|
|
156
270
|
|
|
157
271
|
const parameters = (operation.parameters || []).map(parameter => buildParameter(spec, parameter, id));
|
|
158
272
|
|
|
273
|
+
// Path parameters keep their order in the path, which is the only order that makes
|
|
274
|
+
// sense for them. The other two are grouped required-first: GET /v1/settings carries
|
|
275
|
+
// 87 query parameters, and the handful that are mandatory should not be buried.
|
|
276
|
+
const pathParams = parameters.filter(parameter => parameter.in === 'path');
|
|
277
|
+
const queryParams = requiredFirst(parameters.filter(parameter => parameter.in === 'query'));
|
|
278
|
+
const headerParams = requiredFirst(parameters.filter(parameter => parameter.in === 'header'));
|
|
279
|
+
|
|
159
280
|
const body = buildBody(spec, operation.requestBody, id);
|
|
160
281
|
|
|
161
282
|
// Behavior notes (lib/api-routes/behavior-notes.js): things the schemas cannot express,
|
|
@@ -182,18 +303,22 @@ function buildOperation(spec, path, method, operation, tagName) {
|
|
|
182
303
|
method: method.toLowerCase(),
|
|
183
304
|
methodLabel: method.toUpperCase(),
|
|
184
305
|
methodVariant: methodVariant(method),
|
|
306
|
+
// What the Try it panel warns about, if anything
|
|
307
|
+
tryImpact: tryImpact(operation, method),
|
|
185
308
|
path,
|
|
186
309
|
summary: operation.summary || '',
|
|
187
310
|
descriptionHtml: formatDescription(prose.join('\n\n')),
|
|
188
311
|
deprecated: !!operation.deprecated,
|
|
189
312
|
tag: tagName,
|
|
190
313
|
tagSlug: slugify(tagName),
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
314
|
+
pathParams,
|
|
315
|
+
queryParams,
|
|
316
|
+
headerParams,
|
|
317
|
+
// Set only when the group is really a flag list; reference/params renders those as a
|
|
318
|
+
// chip grid instead of a row each. Query only: flagNames() needs an optional group,
|
|
319
|
+
// and lib/openapi/build-document.js marks every path parameter required, while the
|
|
320
|
+
// largest header group in the document is two entries.
|
|
321
|
+
queryFlags: flagNames(queryParams),
|
|
197
322
|
body,
|
|
198
323
|
responses: buildResponses(spec, operation.responses, id)
|
|
199
324
|
};
|