emailengine-app 2.77.0 → 2.79.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/test.yml +80 -0
- package/.ncurc.js +23 -13
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +60 -0
- package/bin/emailengine.js +1 -1
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +1 -1
- package/lib/account/expected-identity.js +88 -0
- package/lib/account.js +145 -61
- package/lib/api-reference/format.js +105 -4
- package/lib/api-reference/index.js +24 -7
- package/lib/api-reference/model.js +148 -21
- package/lib/api-reference/schema-tree.js +282 -28
- package/lib/api-routes/account-routes.js +99 -36
- package/lib/api-routes/behavior-notes.js +3 -0
- 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 +397 -0
- package/lib/api-routes/route-helpers.js +223 -9
- package/lib/api-routes/route-metadata.js +28 -0
- package/lib/api-routes/settings-routes.js +30 -25
- 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 +319 -33
- package/lib/api-routes/webhook-route-routes.js +14 -4
- package/lib/append-list.js +3 -14
- package/lib/arf-detect.js +23 -1
- package/lib/auth-token.js +80 -8
- package/lib/autodetect-imap-settings.js +40 -16
- package/lib/base32.js +30 -0
- package/lib/bounce-detect.js +182 -62
- package/lib/consts.js +10 -0
- package/lib/db.js +20 -2
- package/lib/delivery-error.js +30 -1
- package/lib/egress-filter.js +89 -8
- package/lib/email-client/base-client.js +35 -113
- package/lib/email-client/gmail-client.js +22 -13
- package/lib/email-client/imap/listing-diff.js +3 -3
- package/lib/email-client/imap/mailbox.js +28 -93
- 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 +39 -28
- package/lib/email-client/message-builder.js +15 -15
- 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 +54 -55
- package/lib/email-client/smtp-pool-manager.js +1 -1
- package/lib/enum-descriptions.js +92 -2
- package/lib/export.js +2 -2
- package/lib/field-usage.js +133 -0
- package/lib/gateway.js +2 -2
- package/lib/get-raw-email.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 +17 -7
- package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
- package/lib/imapproxy/imap-server.js +40 -10
- package/lib/license-beacon.js +5 -10
- package/lib/lists.js +49 -1
- package/lib/llm-pre-process.js +6 -6
- package/lib/logger.js +5 -1
- package/lib/metrics-collector.js +2 -2
- package/lib/msgpack.js +62 -0
- package/lib/oauth/decode-jwt-payload.js +39 -0
- package/lib/oauth/gmail.js +9 -12
- package/lib/oauth/mail-ru.js +5 -7
- package/lib/oauth/outlook-identity.js +61 -0
- package/lib/oauth/outlook.js +9 -9
- package/lib/oauth/pubsub/google.js +25 -10
- package/lib/oauth/retry-setup.js +38 -0
- package/lib/oauth/scope-checker.js +1 -1
- package/lib/oauth2-apps.js +224 -295
- package/lib/openapi/build-document.js +15 -7
- package/lib/openapi/joi-schema.js +20 -0
- package/lib/outbox.js +145 -14
- package/lib/pre-process.js +9 -9
- package/lib/queue-stats.js +49 -0
- package/lib/read-env-value.js +37 -0
- 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 +223 -155
- package/lib/settings.js +84 -5
- package/lib/sub-script.js +2 -1
- package/lib/swagger-options.js +2 -1
- package/lib/templates.js +5 -5
- package/lib/threads.js +2 -2
- package/lib/token-audit-log.js +208 -0
- package/lib/token-permission-view.js +219 -0
- package/lib/token-permissions.js +172 -0
- package/lib/tokens.js +100 -16
- package/lib/tools.js +259 -85
- package/lib/totp.js +67 -0
- package/lib/ui-routes/account-routes.js +122 -26
- package/lib/ui-routes/admin-config-routes.js +20 -17
- package/lib/ui-routes/admin-entities-routes.js +66 -22
- package/lib/ui-routes/auth-routes.js +36 -48
- package/lib/ui-routes/export-routes.js +10 -4
- package/lib/ui-routes/oauth-config-routes.js +5 -5
- package/lib/ui-routes/reference-routes.js +11 -8
- package/lib/ui-routes/route-helpers.js +79 -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 +294 -0
- package/lib/ui-routes/unsubscribe-routes.js +19 -29
- package/lib/utils/is-email.js +34 -0
- package/lib/utils/network.js +2 -2
- package/lib/utils/to-camel-case.js +17 -0
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-egress.js +37 -0
- package/lib/webhook-routing.js +80 -0
- package/lib/webhooks.js +21 -15
- package/package.json +26 -27
- package/sbom.json +1 -0
- package/server.js +81 -42
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +3 -0
- package/static/css/src/app.tailwind.css +159 -9
- package/static/js/app.js +69 -0
- package/static/js/reference.js +741 -10
- package/static/js/ui.js +43 -0
- package/static/licenses.html +698 -1590
- package/translations/README.md +64 -0
- package/translations/de.mo +0 -0
- package/translations/de.po +164 -120
- package/translations/en.po +200 -161
- package/translations/et.mo +0 -0
- package/translations/et.po +163 -120
- package/translations/fr.mo +0 -0
- package/translations/fr.po +163 -120
- package/translations/ja.mo +0 -0
- package/translations/ja.po +163 -120
- package/translations/messages.pot +94 -64
- package/translations/nl.mo +0 -0
- package/translations/nl.po +164 -120
- package/translations/pl.mo +0 -0
- package/translations/pl.po +163 -120
- package/views/account-identity-error.hbs +34 -0
- package/views/accounts/account.hbs +69 -7
- package/views/accounts/browse.hbs +18 -35
- package/views/accounts/edit.hbs +1 -0
- package/views/accounts/register/imap.hbs +12 -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/layout/app.hbs +29 -5
- package/views/oauth-scope-error.hbs +1 -1
- package/views/partials/oauth_form.hbs +0 -15
- package/views/partials/reference/disclosure.hbs +8 -2
- package/views/partials/reference/nav.hbs +36 -9
- package/views/partials/reference/operation.hbs +48 -14
- package/views/partials/reference/params.hbs +17 -1
- package/views/partials/reference/schema-node.hbs +112 -54
- package/views/partials/reference/schema-tools.hbs +25 -0
- package/views/partials/reference/token-alert.hbs +35 -10
- 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/index.hbs +1 -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 +8 -2
- package/views/tokens/index.hbs +31 -4
- package/views/tokens/new.hbs +324 -2
- package/workers/api.js +299 -140
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +13 -7
- package/workers/smtp.js +13 -7
- package/workers/submit.js +41 -31
- package/workers/webhooks.js +60 -37
- package/lib/feature-flags.js +0 -48
package/workers/webhooks.js
CHANGED
|
@@ -10,9 +10,11 @@ const { webhooks: Webhooks } = require('../lib/webhooks');
|
|
|
10
10
|
|
|
11
11
|
const { GooglePubSub } = require('../lib/oauth/pubsub/google');
|
|
12
12
|
|
|
13
|
-
const { readEnvValue, threadStats, getDuration, httpAgent, getServiceSecret, maybeReloadHttpProxyAgent } = require('../lib/tools');
|
|
13
|
+
const { readEnvValue, threadStats, getDuration, httpAgent, getServiceSecret, maybeReloadHttpProxyAgent, redactUrlCredentials } = require('../lib/tools');
|
|
14
14
|
const { sendWebhookRequest } = require('../lib/webhook-request');
|
|
15
|
-
const {
|
|
15
|
+
const { willBeFinalAttempt, isFinalFailedAttempt } = require('../lib/delivery-error');
|
|
16
|
+
const { validateWebhookTarget } = require('../lib/webhook-egress');
|
|
17
|
+
const { resolveTargetUrl, isDeliverableRoute, eventAllowed } = require('../lib/webhook-routing');
|
|
16
18
|
|
|
17
19
|
const { initSentry } = require('../lib/sentry');
|
|
18
20
|
initSentry('webhooks');
|
|
@@ -40,16 +42,10 @@ const NOTIFY_QC = (readEnvValue('EENGINE_NOTIFY_QC') && Number(readEnvValue('EEN
|
|
|
40
42
|
// DEFAULT_WEBHOOK_REQUEST_TIMEOUT baked into sendWebhookRequest when unset
|
|
41
43
|
const WEBHOOK_TIMEOUT = getDuration(readEnvValue('EENGINE_WEBHOOK_TIMEOUT')) || false;
|
|
42
44
|
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
// disables the check and restores redirect following. See lib/egress-filter.js
|
|
48
|
-
const WEBHOOK_EGRESS_POLICY = normalizePolicy(readEnvValue('EENGINE_WEBHOOK_EGRESS_POLICY'));
|
|
49
|
-
|
|
50
|
-
// Built once rather than per delivery. Null when the policy is off, which also restores fetch's
|
|
51
|
-
// own redirect following in sendWebhookRequest().
|
|
52
|
-
const validateWebhookTarget = WEBHOOK_EGRESS_POLICY === POLICY_OFF ? null : target => assertAllowedUrl(target, { policy: WEBHOOK_EGRESS_POLICY });
|
|
45
|
+
// Neither of these changes on a retry: the egress policy rejects the same destination every time,
|
|
46
|
+
// and an endpoint configured to redirect keeps redirecting. Such a delivery is final on its first
|
|
47
|
+
// failure, which decides both the log level and whether the remaining attempts are spent.
|
|
48
|
+
const isUnrecoverableWebhookError = err => !!err && (err.code === 'EEGRESSBLOCKED' || err.code === 'EREDIRECTNOTFOLLOWED');
|
|
53
49
|
|
|
54
50
|
let callQueue = new Map();
|
|
55
51
|
let mids = 0;
|
|
@@ -207,11 +203,18 @@ const notifyWorker = new Worker(
|
|
|
207
203
|
//return new Promise((resolve, reject) => {});
|
|
208
204
|
let accountKey = getAccountKey(job.data.account);
|
|
209
205
|
|
|
206
|
+
// Keep the route id reachable for the completed/failed event handlers, which see this same
|
|
207
|
+
// job instance after _route has been deleted from the payload. Stashed before the early
|
|
208
|
+
// returns below so a job that never reaches delivery still reports which route queued it.
|
|
209
|
+
if (job.data._route && job.data._route.id) {
|
|
210
|
+
job.__routeId = job.data._route.id;
|
|
211
|
+
}
|
|
212
|
+
|
|
210
213
|
// validate if we should even process this webhook
|
|
211
214
|
let accountExists = await redis.hexists(accountKey, 'account');
|
|
212
215
|
if (!accountExists && job.name !== ACCOUNT_DELETED_NOTIFY) {
|
|
213
216
|
logger.debug({
|
|
214
|
-
msg: 'Account
|
|
217
|
+
msg: 'Account not found',
|
|
215
218
|
action: 'webhook',
|
|
216
219
|
queue: job.queue.name,
|
|
217
220
|
code: 'account_not_found',
|
|
@@ -233,14 +236,15 @@ const notifyWorker = new Worker(
|
|
|
233
236
|
customRoute = await Webhooks.getMeta(job.data._route.id);
|
|
234
237
|
customMapping = job.data._route.mapping;
|
|
235
238
|
delete job.data._route;
|
|
236
|
-
if (!customRoute
|
|
239
|
+
if (!isDeliverableRoute(customRoute)) {
|
|
237
240
|
return;
|
|
238
241
|
}
|
|
239
242
|
}
|
|
240
243
|
|
|
241
244
|
let accountWebhooks = await redis.hget(accountKey, 'webhooks');
|
|
242
245
|
|
|
243
|
-
|
|
246
|
+
// the global setting is only fetched when neither a custom route nor the account override decides the target
|
|
247
|
+
let webhooks = resolveTargetUrl(customRoute && customRoute.targetUrl, accountWebhooks, null).url || (await settings.get('webhooks'));
|
|
244
248
|
if (!webhooks) {
|
|
245
249
|
// logger.debug({ msg: 'Webhook URL is not set', action: 'webhook', event: job.name, account: job.data.account });
|
|
246
250
|
return;
|
|
@@ -252,12 +256,13 @@ const notifyWorker = new Worker(
|
|
|
252
256
|
try {
|
|
253
257
|
accountWebhooksCustomHeaders = JSON.parse(accountWebhooksCustomHeadersJson);
|
|
254
258
|
} catch (err) {
|
|
259
|
+
// do not log the header values, they may carry authentication secrets
|
|
255
260
|
logger.debug({
|
|
256
261
|
msg: 'Failed to parse custom webhook headers',
|
|
257
262
|
action: 'webhook',
|
|
258
263
|
event: job.name,
|
|
259
264
|
account: job.data.account,
|
|
260
|
-
|
|
265
|
+
jsonLength: accountWebhooksCustomHeadersJson.length,
|
|
261
266
|
err
|
|
262
267
|
});
|
|
263
268
|
}
|
|
@@ -266,7 +271,7 @@ const notifyWorker = new Worker(
|
|
|
266
271
|
if (!customRoute) {
|
|
267
272
|
// custom routes have their own mappings
|
|
268
273
|
let webhookEvents = (await settings.get('webhookEvents')) || [];
|
|
269
|
-
if (!webhookEvents
|
|
274
|
+
if (!eventAllowed(webhookEvents, job.name)) {
|
|
270
275
|
logger.trace({
|
|
271
276
|
msg: 'Webhook event not in whitelist',
|
|
272
277
|
action: 'webhook',
|
|
@@ -275,8 +280,7 @@ const notifyWorker = new Worker(
|
|
|
275
280
|
job: job.id,
|
|
276
281
|
event: job.name,
|
|
277
282
|
account: job.data.account,
|
|
278
|
-
webhookEvents
|
|
279
|
-
data: job.data
|
|
283
|
+
webhookEvents
|
|
280
284
|
});
|
|
281
285
|
return;
|
|
282
286
|
}
|
|
@@ -342,13 +346,18 @@ const notifyWorker = new Worker(
|
|
|
342
346
|
}
|
|
343
347
|
}
|
|
344
348
|
|
|
349
|
+
// never log the raw target URL, it may embed basic auth credentials; keep the redacted
|
|
350
|
+
// form reachable for the failed event handler
|
|
351
|
+
let redactedWebhooks = redactUrlCredentials(webhooks);
|
|
352
|
+
job.__redactedTargetUrl = redactedWebhooks;
|
|
353
|
+
|
|
345
354
|
logger.trace({
|
|
346
355
|
msg: 'Processing webhook',
|
|
347
356
|
action: 'webhook',
|
|
348
357
|
queue: job.queue.name,
|
|
349
358
|
code: 'processing',
|
|
350
359
|
job: job.id,
|
|
351
|
-
webhooks,
|
|
360
|
+
webhooks: redactedWebhooks,
|
|
352
361
|
accountWebhooks: !!accountWebhooks,
|
|
353
362
|
event: job.name,
|
|
354
363
|
data: filteredData,
|
|
@@ -424,7 +433,7 @@ const notifyWorker = new Worker(
|
|
|
424
433
|
method: 'post',
|
|
425
434
|
body,
|
|
426
435
|
headers,
|
|
427
|
-
dispatcher: httpAgent.
|
|
436
|
+
dispatcher: httpAgent.webhook,
|
|
428
437
|
timeout: WEBHOOK_TIMEOUT,
|
|
429
438
|
validateTarget: validateWebhookTarget
|
|
430
439
|
});
|
|
@@ -440,7 +449,7 @@ const notifyWorker = new Worker(
|
|
|
440
449
|
queue: job.queue.name,
|
|
441
450
|
code: 'result_success',
|
|
442
451
|
job: job.id,
|
|
443
|
-
webhooks,
|
|
452
|
+
webhooks: redactedWebhooks,
|
|
444
453
|
requestBodySize: body.length,
|
|
445
454
|
accountWebhooks: !!accountWebhooks,
|
|
446
455
|
event: job.name,
|
|
@@ -466,13 +475,16 @@ const notifyWorker = new Worker(
|
|
|
466
475
|
status: 'success'
|
|
467
476
|
});
|
|
468
477
|
} catch (err) {
|
|
469
|
-
|
|
478
|
+
// egress and redirect failures are thrown as UnrecoverableError below, so they are final as well
|
|
479
|
+
let isFinalAttempt = willBeFinalAttempt(job) || isUnrecoverableWebhookError(err);
|
|
480
|
+
|
|
481
|
+
logger[isFinalAttempt ? 'error' : 'warn']({
|
|
470
482
|
msg: 'Failed posting webhook',
|
|
471
483
|
action: 'webhook',
|
|
472
484
|
queue: job.queue.name,
|
|
473
485
|
code: 'result_fail',
|
|
474
486
|
job: job.id,
|
|
475
|
-
webhooks,
|
|
487
|
+
webhooks: redactedWebhooks,
|
|
476
488
|
requestBodySize: body.length,
|
|
477
489
|
accountWebhooks: !!accountWebhooks,
|
|
478
490
|
event: job.name,
|
|
@@ -527,12 +539,14 @@ const notifyWorker = new Worker(
|
|
|
527
539
|
status: 'fail'
|
|
528
540
|
});
|
|
529
541
|
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
542
|
+
// Spending the remaining attempts on an unrecoverable failure only delays the operator
|
|
543
|
+
// seeing the real reason in the error flag. Fail the job now and keep the message.
|
|
544
|
+
if (isUnrecoverableWebhookError(err)) {
|
|
545
|
+
// UnrecoverableError copies the message only, and the failed-event handler logs the
|
|
546
|
+
// error it is given, so carry the code over or that log loses the actual reason
|
|
547
|
+
let unrecoverableErr = new UnrecoverableError(err.message);
|
|
548
|
+
unrecoverableErr.code = err.code;
|
|
549
|
+
throw unrecoverableErr;
|
|
536
550
|
}
|
|
537
551
|
|
|
538
552
|
throw err;
|
|
@@ -567,31 +581,40 @@ notifyWorker.on('completed', async job => {
|
|
|
567
581
|
status: 'completed'
|
|
568
582
|
});
|
|
569
583
|
|
|
570
|
-
logger.
|
|
584
|
+
logger.debug({
|
|
571
585
|
msg: 'Notification queue entry completed',
|
|
572
586
|
action: 'webhook',
|
|
573
587
|
queue: job.queue.name,
|
|
574
588
|
code: 'completed',
|
|
575
589
|
job: job.id,
|
|
590
|
+
event: job.name,
|
|
576
591
|
account: job.data.account,
|
|
577
|
-
|
|
592
|
+
// a completed job always ran the processor, which stashes this before any early return
|
|
593
|
+
route: job.__routeId
|
|
578
594
|
});
|
|
579
595
|
});
|
|
580
596
|
|
|
581
|
-
notifyWorker.on('failed', async job => {
|
|
597
|
+
notifyWorker.on('failed', async (job, err) => {
|
|
582
598
|
metrics(logger, 'queuesProcessed', 'inc', {
|
|
583
599
|
queue: 'notify',
|
|
584
600
|
status: 'failed'
|
|
585
601
|
});
|
|
586
602
|
|
|
587
|
-
|
|
603
|
+
let isFinal = isFinalFailedAttempt(job);
|
|
604
|
+
|
|
605
|
+
logger[isFinal ? 'error' : 'debug']({
|
|
588
606
|
msg: 'Notification queue entry failed',
|
|
589
607
|
action: 'webhook',
|
|
590
608
|
queue: job.queue.name,
|
|
591
609
|
code: 'failed',
|
|
592
610
|
job: job.id,
|
|
611
|
+
event: job.name,
|
|
593
612
|
account: job.data.account,
|
|
594
|
-
|
|
613
|
+
// the fallback covers jobs that stalled out before this worker instance ever processed
|
|
614
|
+
// them, where the stash was never set and _route is still in the payload
|
|
615
|
+
route: job.__routeId || (job.data._route && job.data._route.id),
|
|
616
|
+
webhooks: job.__redactedTargetUrl,
|
|
617
|
+
err,
|
|
595
618
|
|
|
596
619
|
failedReason: job.failedReason,
|
|
597
620
|
stacktrace: job.stacktrace,
|
|
@@ -612,10 +635,10 @@ let startRetryTimer = null;
|
|
|
612
635
|
let delay;
|
|
613
636
|
if (attempt < maxNormalAttempts) {
|
|
614
637
|
delay = Math.min(5000 * Math.pow(2, Math.min(attempt, 10)), 60000);
|
|
615
|
-
logger.
|
|
638
|
+
logger.warn({ msg: 'Failed to start processing Google pub/sub', err, attempt: attempt + 1, retryMs: delay });
|
|
616
639
|
} else {
|
|
617
640
|
delay = 5 * 60 * 1000;
|
|
618
|
-
logger.
|
|
641
|
+
logger.error({ msg: 'Failed to start processing Google pub/sub (reduced frequency)', err, attempt: attempt + 1, retryMs: delay });
|
|
619
642
|
}
|
|
620
643
|
startRetryTimer = setTimeout(() => startGooglePubSub(attempt + 1), delay);
|
|
621
644
|
});
|
package/lib/feature-flags.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const logger = require('./logger');
|
|
4
|
-
|
|
5
|
-
const FEATURES = new Set();
|
|
6
|
-
|
|
7
|
-
const ENABLED_FEATURES = [];
|
|
8
|
-
|
|
9
|
-
const formatFeatureKey = key =>
|
|
10
|
-
(key || '')
|
|
11
|
-
.toString()
|
|
12
|
-
.trim()
|
|
13
|
-
.toLowerCase()
|
|
14
|
-
.replace(/[-_\s]+/g, '_');
|
|
15
|
-
|
|
16
|
-
for (let feature of ENABLED_FEATURES) {
|
|
17
|
-
FEATURES.add(formatFeatureKey(feature));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
for (let key of Object.keys(process.env)) {
|
|
21
|
-
if (/^EENGINE_FEATURE_/i.test(key)) {
|
|
22
|
-
let feature = formatFeatureKey(key.substring('EENGINE_FEATURE_'.length));
|
|
23
|
-
if (feature) {
|
|
24
|
-
let value = /^(y|yes|true|t|1)$/i.test((process.env[key] || '').toString().trim());
|
|
25
|
-
if (value) {
|
|
26
|
-
FEATURES.add(feature);
|
|
27
|
-
} else {
|
|
28
|
-
FEATURES.delete(feature);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = {
|
|
35
|
-
enabled(key) {
|
|
36
|
-
return FEATURES.has(formatFeatureKey(key));
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
// Sorted list of the currently enabled feature flag keys. Used by the license beacon
|
|
40
|
-
// to report which EENGINE_FEATURE_* flags are active on this instance.
|
|
41
|
-
listEnabled() {
|
|
42
|
-
return Array.from(FEATURES).sort();
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
if (FEATURES.size > 0) {
|
|
47
|
-
logger.info({ msg: 'Enabled feature flags', featureFlags: Array.from(FEATURES) });
|
|
48
|
-
}
|