emailengine-app 2.83.0 → 2.83.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +11 -0
- package/lib/api-reference/format.js +1 -1
- package/lib/api-routes/export-routes.js +5 -5
- package/lib/api-routes/oauth2-app-routes.js +4 -1
- package/lib/api-routes/route-helpers.js +11 -5
- package/lib/oauth/gcp-metadata.js +50 -13
- package/lib/oauth/gmail.js +12 -6
- package/lib/oauth/verify-app.js +8 -2
- package/lib/oauth2-apps.js +26 -6
- package/lib/swagger-options.js +2 -3
- package/lib/ui-routes/oauth-config-routes.js +14 -15
- package/lib/ui-routes/oauth-form-context.js +19 -0
- package/package.json +1 -1
- package/static/css/flyonui.css +1 -1
- package/views/accounts/account.hbs +0 -5
- package/views/config/oauth/edit.hbs +0 -10
- package/views/config/oauth/new.hbs +0 -10
- package/views/partials/oauth_form.hbs +426 -928
- package/views/partials/oauth_graph_endpoints.hbs +12 -0
- package/views/partials/oauth_pubsub_app_select.hbs +11 -20
- package/views/partials/oauth_scope_presets.hbs +21 -0
- package/views/partials/ui/choice-tab.hbs +23 -0
- package/views/partials/ui/choice-tabs.hbs +32 -0
- package/views/partials/ui/radio.hbs +2 -2
- package/views/partials/ui/secret-field.hbs +2 -1
- package/views/partials/ui/tabs.hbs +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.83.1](https://github.com/postalsys/emailengine/compare/v2.83.0...v2.83.1) (2026-10-08)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* ask a service account app's purpose before its authentication method ([42ac521](https://github.com/postalsys/emailengine/commit/42ac521021fabe8976fd86f13da6e8c6d1707ac3))
|
|
9
|
+
* close the attached service account review findings ([d567ad8](https://github.com/postalsys/emailengine/commit/d567ad866f90e0ced6b2b1d8fa722e7a74d6ac25))
|
|
10
|
+
* drop the beta label from the export API ([21df0b0](https://github.com/postalsys/emailengine/commit/21df0b0e4ad5bb1ef18ce3eb916fa77e9028075d))
|
|
11
|
+
* keep the OAuth2 app routes inside their size budget ([8a72c20](https://github.com/postalsys/emailengine/commit/8a72c20188aad62d7cb32401d98869c1ed96a75a))
|
|
12
|
+
* rework the OAuth2 app form around what each app connects with ([a000412](https://github.com/postalsys/emailengine/commit/a000412ecc2c233f9fb4cc50fe8486904692a8ba))
|
|
13
|
+
|
|
3
14
|
## [2.83.0](https://github.com/postalsys/emailengine/compare/v2.82.2...v2.83.0) (2026-10-08)
|
|
4
15
|
|
|
5
16
|
|
|
@@ -60,7 +60,7 @@ function formatDescription(text) {
|
|
|
60
60
|
.join('</p><p class="mt-2">');
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
// URL segment for a tag name: "
|
|
63
|
+
// URL segment for a tag name: "Multi Message Actions" -> "multi-message-actions"
|
|
64
64
|
function slugify(value) {
|
|
65
65
|
return String(value || '')
|
|
66
66
|
.toLowerCase()
|
|
@@ -34,7 +34,7 @@ async function init(args) {
|
|
|
34
34
|
options: {
|
|
35
35
|
description: 'Create export',
|
|
36
36
|
notes: ['Creates a new bulk message export job. The export runs asynchronously and notifies via webhook when complete.', BEHAVIOR.BACKGROUND_JOB],
|
|
37
|
-
tags: ['api', 'Export
|
|
37
|
+
tags: ['api', 'Export'],
|
|
38
38
|
|
|
39
39
|
plugins: {
|
|
40
40
|
openapi: {
|
|
@@ -94,7 +94,7 @@ async function init(args) {
|
|
|
94
94
|
options: {
|
|
95
95
|
description: 'Get export status',
|
|
96
96
|
notes: 'Returns the status and progress of an export job.',
|
|
97
|
-
tags: ['api', 'Export
|
|
97
|
+
tags: ['api', 'Export'],
|
|
98
98
|
|
|
99
99
|
plugins: {
|
|
100
100
|
openapi: {
|
|
@@ -158,7 +158,7 @@ async function init(args) {
|
|
|
158
158
|
options: {
|
|
159
159
|
description: 'Download export file',
|
|
160
160
|
notes: 'Downloads the completed export file as gzip-compressed NDJSON.',
|
|
161
|
-
tags: ['api', 'Export
|
|
161
|
+
tags: ['api', 'Export'],
|
|
162
162
|
|
|
163
163
|
plugins: {
|
|
164
164
|
openapi: {
|
|
@@ -208,7 +208,7 @@ async function init(args) {
|
|
|
208
208
|
options: {
|
|
209
209
|
description: 'Delete export',
|
|
210
210
|
notes: 'Cancels a pending export or deletes a completed export. Removes both Redis data and the export file.',
|
|
211
|
-
tags: ['api', 'Export
|
|
211
|
+
tags: ['api', 'Export'],
|
|
212
212
|
|
|
213
213
|
plugins: {
|
|
214
214
|
openapi: {
|
|
@@ -264,7 +264,7 @@ async function init(args) {
|
|
|
264
264
|
options: {
|
|
265
265
|
description: 'List exports',
|
|
266
266
|
notes: 'Lists all exports for an account with pagination.',
|
|
267
|
-
tags: ['api', 'Export
|
|
267
|
+
tags: ['api', 'Export'],
|
|
268
268
|
|
|
269
269
|
plugins: {
|
|
270
270
|
openapi: {
|
|
@@ -345,7 +345,7 @@ async function init(args) {
|
|
|
345
345
|
|
|
346
346
|
async handler(request) {
|
|
347
347
|
try {
|
|
348
|
-
assertNoAttachedIdentity(request);
|
|
348
|
+
assertNoAttachedIdentity(request, request.payload.authMethod, 'create');
|
|
349
349
|
let result = await oauth2Apps.create(request.payload);
|
|
350
350
|
return await applyPubSubUpdates(result);
|
|
351
351
|
} catch (err) {
|
|
@@ -413,6 +413,9 @@ async function init(args) {
|
|
|
413
413
|
);
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
+
let storedApp = await oauth2Apps.get(request.params.app);
|
|
417
|
+
assertNoAttachedIdentity(request, storedApp && storedApp.authMethod, 'modify');
|
|
418
|
+
|
|
416
419
|
let result = await oauth2Apps.update(request.params.app, request.payload);
|
|
417
420
|
return await applyPubSubUpdates(result);
|
|
418
421
|
} catch (err) {
|
|
@@ -420,18 +420,24 @@ function assertNoPrivilegedSettings(request, keys, verb = 'change') {
|
|
|
420
420
|
* than an app field, so a token narrowed to `oauth2` may manage applications but not lend itself
|
|
421
421
|
* the deployment's identity. The admin interface and an unrestricted token still create these apps.
|
|
422
422
|
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
423
|
+
* Creating one is not the only way in: an update of a saved app re-runs its Pub/Sub setup as that same
|
|
424
|
+
* identity, so moving the project, topic or subscription of an existing attached service account app
|
|
425
|
+
* lends it just the same. Any update of such an app is refused, not only one naming those fields: an
|
|
426
|
+
* allow-list of harmless fields would be one more list to keep right, and the admin interface and an
|
|
427
|
+
* unrestricted token remain. A saved app's method is pinned (isAuthMethodLocked() in
|
|
428
|
+
* lib/oauth2-apps.js), so the stored one is what an update checks.
|
|
425
429
|
*
|
|
426
430
|
* @param {Object} request - the Hapi request
|
|
431
|
+
* @param {string} [authMethod] - the method of the app being created (the payload's) or modified (the stored one's)
|
|
432
|
+
* @param {string} verb - 'create' or 'modify', for the refusal message
|
|
427
433
|
*/
|
|
428
|
-
function assertNoAttachedIdentity(request) {
|
|
429
|
-
if (
|
|
434
|
+
function assertNoAttachedIdentity(request, authMethod, verb) {
|
|
435
|
+
if (authMethod !== 'metadataServer' || !isRestrictedCredential(request)) {
|
|
430
436
|
return;
|
|
431
437
|
}
|
|
432
438
|
|
|
433
439
|
throw Boom.forbidden(
|
|
434
|
-
|
|
440
|
+
`A token with restricted permissions can not ${verb} an application that uses the attached service account (metadataServer). Use the admin interface or an unrestricted token`
|
|
435
441
|
);
|
|
436
442
|
}
|
|
437
443
|
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
// `Metadata-Flavor` header and the http scheme are fixed, so this never becomes a general fetcher.
|
|
15
15
|
//
|
|
16
16
|
// No dependency on lib/tools.js on purpose: that module opens Redis on require, and this one has
|
|
17
|
-
// to stay testable as a pure helper.
|
|
17
|
+
// to stay testable as a pure helper. lib/read-env-value.js is the leaf it splits out for that.
|
|
18
18
|
|
|
19
19
|
const timers = require('timers/promises');
|
|
20
20
|
const { fetch: undiciFetch, Agent } = require('undici');
|
|
21
21
|
const packageData = require('../../package.json');
|
|
22
22
|
const { makeError } = require('./external-account-config');
|
|
23
|
+
const { readEnvValue } = require('../read-env-value');
|
|
23
24
|
|
|
24
25
|
// Google recommends the DNS name over 169.254.169.254, and it fails safer: it resolves only on
|
|
25
26
|
// Google Cloud, so on any other host the request ends at once with ENOTFOUND, instead of waiting
|
|
@@ -64,14 +65,13 @@ const metadataAgent = new Agent({
|
|
|
64
65
|
* query, credentials) is refused rather than replaced by the default: an override that is quietly
|
|
65
66
|
* ignored sends a test setup to the real metadata server, which is the worse way to fail.
|
|
66
67
|
*
|
|
67
|
-
* @param {Object} [env
|
|
68
|
+
* @param {Object} [env] - environment to read (tests); the process environment, through readEnvValue(), when omitted
|
|
68
69
|
* @returns {string} the origin, e.g. `http://metadata.google.internal`
|
|
69
70
|
*/
|
|
70
71
|
function resolveMetadataOrigin(env) {
|
|
71
|
-
env = env || process.env;
|
|
72
|
-
|
|
73
72
|
for (let key of METADATA_HOST_ENV_KEYS) {
|
|
74
|
-
|
|
73
|
+
// readEnvValue() so the <KEY>_FILE form works here as it does for every other value
|
|
74
|
+
let raw = ((env ? env[key] : readEnvValue(key)) || '').toString().trim();
|
|
75
75
|
if (!raw) {
|
|
76
76
|
continue;
|
|
77
77
|
}
|
|
@@ -94,14 +94,44 @@ function resolveMetadataOrigin(env) {
|
|
|
94
94
|
return `http://${DEFAULT_METADATA_HOST}`;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
function isTimeoutError(err) {
|
|
98
|
+
return !!err && (err.name === 'TimeoutError' || err.name === 'AbortError');
|
|
99
|
+
}
|
|
100
|
+
|
|
97
101
|
function describeNetworkError(err) {
|
|
98
102
|
let cause = (err && err.cause) || err;
|
|
99
|
-
if (
|
|
103
|
+
if (isTimeoutError(cause)) {
|
|
100
104
|
return `no answer within ${Math.round(REQUEST_TIMEOUT / 1000)}s`;
|
|
101
105
|
}
|
|
102
106
|
return (cause && (cause.code || cause.message)) || 'connection failed';
|
|
103
107
|
}
|
|
104
108
|
|
|
109
|
+
// Network failures that say the metadata server was there but slow or interrupted, as opposed to
|
|
110
|
+
// absent (ENOTFOUND off Google Cloud) or refusing (ECONNREFUSED at a wrong override). Deliberately
|
|
111
|
+
// not consts.TRANSIENT_NETWORK_CODES, which counts both of those as transient
|
|
112
|
+
const METADATA_TRANSIENT_CODES = new Set([
|
|
113
|
+
'ECONNRESET',
|
|
114
|
+
'ETIMEDOUT',
|
|
115
|
+
'EPIPE',
|
|
116
|
+
'UND_ERR_CONNECT_TIMEOUT',
|
|
117
|
+
'UND_ERR_HEADERS_TIMEOUT',
|
|
118
|
+
'UND_ERR_BODY_TIMEOUT',
|
|
119
|
+
'UND_ERR_SOCKET'
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Whether a failure from this module is worth retrying as is: the metadata server answered 5xx past
|
|
124
|
+
* the maintenance retry, or the request timed out or was cut off. Everything else (no metadata server,
|
|
125
|
+
* no service account, a wrong override, a refused request) needs the operator. Decided where the error
|
|
126
|
+
* is thrown, which is where the underlying failure is in hand.
|
|
127
|
+
*
|
|
128
|
+
* @param {Error} err - an error thrown by fetchAccessToken() and friends
|
|
129
|
+
* @returns {boolean}
|
|
130
|
+
*/
|
|
131
|
+
function isTransientMetadataError(err) {
|
|
132
|
+
return !!(err && err.transient);
|
|
133
|
+
}
|
|
134
|
+
|
|
105
135
|
/**
|
|
106
136
|
* GETs one metadata path and returns the response text.
|
|
107
137
|
*
|
|
@@ -130,8 +160,10 @@ async function metadataRequest(path, opts) {
|
|
|
130
160
|
});
|
|
131
161
|
body = await res.text();
|
|
132
162
|
} catch (err) {
|
|
163
|
+
let cause = err.cause || err;
|
|
133
164
|
throw makeError(`The metadata server at ${origin} could not be reached (${describeNetworkError(err)})`, 'EMetadataUnreachable', null, {
|
|
134
|
-
cause: err
|
|
165
|
+
cause: err,
|
|
166
|
+
transient: isTimeoutError(cause) || METADATA_TRANSIENT_CODES.has(cause.code)
|
|
135
167
|
});
|
|
136
168
|
}
|
|
137
169
|
|
|
@@ -140,12 +172,9 @@ async function metadataRequest(path, opts) {
|
|
|
140
172
|
continue;
|
|
141
173
|
}
|
|
142
174
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
175
|
+
// Before the status: the metadata server flavors its error answers too, and a 404 from a
|
|
176
|
+
// parking host or a cluster's search domain must read as "not the metadata server", not as
|
|
177
|
+
// "no service account attached"
|
|
149
178
|
if (res.headers.get(FLAVOR_HEADER) !== FLAVOR_VALUE) {
|
|
150
179
|
throw makeError(
|
|
151
180
|
`The server at ${origin} is not a Google Cloud metadata server (no "${FLAVOR_HEADER}: ${FLAVOR_VALUE}" header)`,
|
|
@@ -157,6 +186,13 @@ async function metadataRequest(path, opts) {
|
|
|
157
186
|
);
|
|
158
187
|
}
|
|
159
188
|
|
|
189
|
+
if (!res.ok) {
|
|
190
|
+
throw makeError(`The metadata server at ${origin} returned HTTP ${res.status} for ${path}`, 'EMetadataServer', res.status, {
|
|
191
|
+
responseText: body.slice(0, MAX_RESPONSE_TEXT),
|
|
192
|
+
transient: res.status >= 500
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
160
196
|
return body;
|
|
161
197
|
}
|
|
162
198
|
}
|
|
@@ -216,6 +252,7 @@ async function describeAttachedIdentity(opts) {
|
|
|
216
252
|
|
|
217
253
|
module.exports = {
|
|
218
254
|
resolveMetadataOrigin,
|
|
255
|
+
isTransientMetadataError,
|
|
219
256
|
fetchAccessToken,
|
|
220
257
|
fetchServiceAccountEmail,
|
|
221
258
|
describeAttachedIdentity
|
package/lib/oauth/gmail.js
CHANGED
|
@@ -661,12 +661,18 @@ class GmailOauth {
|
|
|
661
661
|
});
|
|
662
662
|
}
|
|
663
663
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
664
|
+
err.tokenRequest = { provider: this.provider, signer: this.authMethod, status: err.statusCode };
|
|
665
|
+
|
|
666
|
+
// A maintenance 503 or a timeout is retried on the next renewal and needs nobody, so it
|
|
667
|
+
// does not flag the app, the same as a network failure on the token endpoint paths
|
|
668
|
+
if (!gcpMetadata.isTransientMetadataError(err)) {
|
|
669
|
+
let flag = {
|
|
670
|
+
message: `Failed to get an access token for the attached service account: ${err.message}`,
|
|
671
|
+
code: 'METADATA_SERVER'
|
|
672
|
+
};
|
|
673
|
+
await this.setFlag(flag);
|
|
674
|
+
err.tokenRequest.flag = flag;
|
|
675
|
+
}
|
|
670
676
|
throw err;
|
|
671
677
|
}
|
|
672
678
|
|
package/lib/oauth/verify-app.js
CHANGED
|
@@ -111,6 +111,9 @@ function metadataServerHint(err) {
|
|
|
111
111
|
case 'EMetadataConfig':
|
|
112
112
|
return 'The metadata server override in the environment is not a host name or host:port. Correct or remove EENGINE_GCP_METADATA_HOST (or GCE_METADATA_HOST).';
|
|
113
113
|
case 'EMetadataUnreachable':
|
|
114
|
+
if (err.transient) {
|
|
115
|
+
return 'The metadata server did not answer in time or dropped the connection. Retry in a moment; if it persists, check the network path to metadata.google.internal from this host.';
|
|
116
|
+
}
|
|
114
117
|
return 'EmailEngine is not running on Google Cloud, or the metadata server cannot be reached from it. The attached service account is only available on Compute Engine, GKE with Workload Identity enabled on the node pool, and Cloud Run. The request never goes through the configured proxy.';
|
|
115
118
|
case 'EMetadataServer':
|
|
116
119
|
if (err.wrongFlavor) {
|
|
@@ -143,8 +146,11 @@ async function pubSubAccessProbe(appData, client, accessToken, steps) {
|
|
|
143
146
|
return;
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
// the
|
|
147
|
-
|
|
149
|
+
// The stored topic is the one the Gmail watches publish to, and it does not always follow the
|
|
150
|
+
// current project and topic name (an adopted topic is kept as recorded), so it is the one to
|
|
151
|
+
// probe. Before the first setup there is none, and the name that setup creates is probed instead
|
|
152
|
+
// (both parts pattern-validated, so neither can leave the path)
|
|
153
|
+
let topicName = appData.pubSubTopic || `projects/${appData.googleProjectId}/topics/${pubSubResourceNames(appData).topic}`;
|
|
148
154
|
|
|
149
155
|
try {
|
|
150
156
|
await client.request(accessToken, `https://pubsub.googleapis.com/v1/${topicName}`, 'get');
|
package/lib/oauth2-apps.js
CHANGED
|
@@ -67,6 +67,11 @@ const authFlagClearChecks = new Map();
|
|
|
67
67
|
// Used when a token response carries no usable expires_in (Google's service tokens live an hour)
|
|
68
68
|
const DEFAULT_SERVICE_TOKEN_TTL = 3600;
|
|
69
69
|
|
|
70
|
+
// The service account fields the attached service account never reads: the metadata server alone
|
|
71
|
+
// decides which account the tokens belong to, so a stored address would name a principal the app
|
|
72
|
+
// does not act as, and operators granting roles to it would grant them to the wrong one
|
|
73
|
+
const SERVICE_ACCOUNT_IDENTITY_FIELDS = ['serviceClient', 'serviceClientEmail'];
|
|
74
|
+
|
|
70
75
|
// Drops the credentials a gmailService app's method does not use, so nothing is stored that the app
|
|
71
76
|
// would never present
|
|
72
77
|
function withoutOtherCredentials(data, authMethod) {
|
|
@@ -76,6 +81,11 @@ function withoutOtherCredentials(data, authMethod) {
|
|
|
76
81
|
delete result[field];
|
|
77
82
|
}
|
|
78
83
|
}
|
|
84
|
+
if (authMethod === 'metadataServer') {
|
|
85
|
+
for (let field of SERVICE_ACCOUNT_IDENTITY_FIELDS) {
|
|
86
|
+
delete result[field];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
79
89
|
return result;
|
|
80
90
|
}
|
|
81
91
|
|
|
@@ -153,7 +163,12 @@ function oauth2ProviderData(provider, selector) {
|
|
|
153
163
|
// field and not on the provider, so a service account delegated gmail.modify is as API-based
|
|
154
164
|
// as an interactive app. The form guards the controls that only make sense in that mode - the
|
|
155
165
|
// scope presets, the Pub/Sub service account - on this rather than on one provider name.
|
|
156
|
-
gmailApi: GMAIL_PROVIDERS.has(provider)
|
|
166
|
+
gmailApi: GMAIL_PROVIDERS.has(provider),
|
|
167
|
+
// The two Microsoft providers share their fields (client ID label, Azure cloud), and the two
|
|
168
|
+
// app-only providers share their account rules; the admin form reads these instead of
|
|
169
|
+
// repeating each provider name
|
|
170
|
+
microsoft: provider === 'outlook' || provider === 'outlookService',
|
|
171
|
+
serviceAccount: SERVICE_ACCOUNT_PROVIDERS.has(provider)
|
|
157
172
|
};
|
|
158
173
|
|
|
159
174
|
switch (provider) {
|
|
@@ -787,13 +802,13 @@ class OAuth2AppsHandler {
|
|
|
787
802
|
externalAccountSigners.delete(id);
|
|
788
803
|
}
|
|
789
804
|
|
|
790
|
-
// The authentication method is fixed once an app is saved: pin the stored one and drop the
|
|
791
|
-
// other methods' credentials. The admin form's update schema defaults an omitted authMethod
|
|
805
|
+
// The authentication method is fixed once an app is saved: pin the stored one, and drop the
|
|
806
|
+
// other methods' credentials from the merged record below. The admin form's update schema defaults an omitted authMethod
|
|
792
807
|
// to serviceKey, which would otherwise turn an attached service account app into a keyless
|
|
793
808
|
// key-signed one
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
data =
|
|
809
|
+
let lockedAuthMethod = isAuthMethodLocked(existingData) ? normalizeAuthMethod(existingData.authMethod) : null;
|
|
810
|
+
if (lockedAuthMethod) {
|
|
811
|
+
data = Object.assign({}, data || {}, { authMethod: lockedAuthMethod });
|
|
797
812
|
}
|
|
798
813
|
|
|
799
814
|
let oldPubSubApp = existingData.pubSubApp || null;
|
|
@@ -810,6 +825,11 @@ class OAuth2AppsHandler {
|
|
|
810
825
|
created: existingData.created,
|
|
811
826
|
updated: new Date().toISOString()
|
|
812
827
|
});
|
|
828
|
+
if (lockedAuthMethod) {
|
|
829
|
+
// on the merged record rather than the update alone, so a field saved before the method's
|
|
830
|
+
// rules were this strict is cleared by the next write instead of kept forever
|
|
831
|
+
entry = withoutOtherCredentials(entry, lockedAuthMethod);
|
|
832
|
+
}
|
|
813
833
|
|
|
814
834
|
let updates = {
|
|
815
835
|
[`${id}:data`]: msgpack.encode(entry)
|
package/lib/swagger-options.js
CHANGED
|
@@ -162,9 +162,8 @@ Full documentation: https://learn.emailengine.app/`
|
|
|
162
162
|
description: 'Perform bulk operations on multiple messages simultaneously, such as marking as read, moving, or deleting'
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
|
-
name: 'Export
|
|
166
|
-
description:
|
|
167
|
-
'Bulk export messages from email accounts. This feature is in beta and the API may change in future releases. Export files are encrypted at rest when a service secret is configured.'
|
|
165
|
+
name: 'Export',
|
|
166
|
+
description: 'Bulk export messages from email accounts. Export files are encrypted at rest when a service secret is configured.'
|
|
168
167
|
}
|
|
169
168
|
],
|
|
170
169
|
|
|
@@ -21,6 +21,7 @@ const { authMethodContext, gmailServiceAuthRoutes } = require('./gmail-service-a
|
|
|
21
21
|
const { isSendOnlyGmailApp } = require('../oauth/scope-checker');
|
|
22
22
|
const { oauthCreateSchema, oauthUpdateSchema, accountIdSchema, formBoolean } = require('../schemas');
|
|
23
23
|
const { throwAsBoom, adminUrl, submittedValues, windowedPageLinks } = require('./route-helpers');
|
|
24
|
+
const { baseScopesContext } = require('./oauth-form-context');
|
|
24
25
|
|
|
25
26
|
const { DEFAULT_PAGE_SIZE } = consts;
|
|
26
27
|
|
|
@@ -88,9 +89,7 @@ function init(args) {
|
|
|
88
89
|
|
|
89
90
|
pubSubApps: await getPubSubAppsForSelect(payload.pubSubApp),
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
baseScopesImap: payload.baseScopes === 'imap' || !payload.baseScopes,
|
|
93
|
-
baseScopesPubsub: payload.baseScopes === 'pubsub',
|
|
92
|
+
...baseScopesContext(payload.baseScopes),
|
|
94
93
|
|
|
95
94
|
azureClouds: structuredClone(AZURE_CLOUDS).map(entry => {
|
|
96
95
|
entry.selected = payload.cloud === entry.id;
|
|
@@ -453,9 +452,7 @@ function init(args) {
|
|
|
453
452
|
|
|
454
453
|
app,
|
|
455
454
|
|
|
456
|
-
|
|
457
|
-
baseScopesImap: app.baseScopes === 'imap' || !app.baseScopes,
|
|
458
|
-
baseScopesPubsub: app.baseScopes === 'pubsub',
|
|
455
|
+
...baseScopesContext(app.baseScopes),
|
|
459
456
|
|
|
460
457
|
appShowAuthMethod: app.provider === 'gmailService',
|
|
461
458
|
...authMethodContext(app.authMethod),
|
|
@@ -653,9 +650,13 @@ function init(args) {
|
|
|
653
650
|
method: 'GET',
|
|
654
651
|
path: '/admin/config/oauth/new',
|
|
655
652
|
async handler(request, h) {
|
|
656
|
-
let { provider } = request.query;
|
|
653
|
+
let { provider, baseScopes } = request.query;
|
|
657
654
|
let providerData = oauth2ProviderData(provider);
|
|
658
655
|
|
|
656
|
+
// A Pub/Sub app is a gmailService app with the pubsub base scope, and the Gmail API forms link
|
|
657
|
+
// here to create one, preselected. Any other provider keeps the IMAP default
|
|
658
|
+
let preselectPubsub = provider === 'gmailService' && baseScopes === 'pubsub';
|
|
659
|
+
|
|
659
660
|
let serviceUrl = await settings.get('serviceUrl');
|
|
660
661
|
let defaultRedirectUrl = `${serviceUrl}/oauth`;
|
|
661
662
|
if (provider === 'outlook') {
|
|
@@ -674,9 +675,7 @@ function init(args) {
|
|
|
674
675
|
providerData,
|
|
675
676
|
defaultRedirectUrl,
|
|
676
677
|
|
|
677
|
-
|
|
678
|
-
baseScopesApi: false,
|
|
679
|
-
baseScopesPubsub: false,
|
|
678
|
+
...baseScopesContext(preselectPubsub ? 'pubsub' : 'imap'),
|
|
680
679
|
|
|
681
680
|
...authMethodContext('serviceKey'),
|
|
682
681
|
|
|
@@ -692,7 +691,8 @@ function init(args) {
|
|
|
692
691
|
values: {
|
|
693
692
|
provider,
|
|
694
693
|
redirectUrl: defaultRedirectUrl,
|
|
695
|
-
authMethod: 'serviceKey'
|
|
694
|
+
authMethod: 'serviceKey',
|
|
695
|
+
enabled: true
|
|
696
696
|
},
|
|
697
697
|
|
|
698
698
|
authorityCommon: true
|
|
@@ -720,7 +720,8 @@ function init(args) {
|
|
|
720
720
|
.empty('')
|
|
721
721
|
.valid(...Object.keys(OAUTH_PROVIDERS))
|
|
722
722
|
.label('Provider')
|
|
723
|
-
.required()
|
|
723
|
+
.required(),
|
|
724
|
+
baseScopes: Joi.string().empty('').valid('pubsub').label('Base scopes')
|
|
724
725
|
})
|
|
725
726
|
}
|
|
726
727
|
}
|
|
@@ -854,9 +855,7 @@ function init(args) {
|
|
|
854
855
|
|
|
855
856
|
values,
|
|
856
857
|
|
|
857
|
-
|
|
858
|
-
baseScopesImap: values.baseScopes === 'imap' || !values.baseScopes,
|
|
859
|
-
baseScopesPubsub: values.baseScopes === 'pubsub',
|
|
858
|
+
...baseScopesContext(values.baseScopes),
|
|
860
859
|
|
|
861
860
|
azureClouds: structuredClone(AZURE_CLOUDS).map(entry => {
|
|
862
861
|
entry.selected = values.cloud === entry.id;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Render-context booleans for the OAuth2 app form's base scope radios and the sections they reveal,
|
|
5
|
+
* shared by the create, edit and app pages and their validation re-renders. A missing scope is an
|
|
6
|
+
* app stored before base scopes existed, which used IMAP and SMTP.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} [baseScopes] - 'imap', 'api' or 'pubsub'
|
|
9
|
+
* @returns {{baseScopesApi: boolean, baseScopesImap: boolean, baseScopesPubsub: boolean}}
|
|
10
|
+
*/
|
|
11
|
+
function baseScopesContext(baseScopes) {
|
|
12
|
+
return {
|
|
13
|
+
baseScopesApi: baseScopes === 'api',
|
|
14
|
+
baseScopesImap: baseScopes === 'imap' || !baseScopes,
|
|
15
|
+
baseScopesPubsub: baseScopes === 'pubsub'
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = { baseScopesContext };
|