mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
merge dev into feat/postgres-support
This commit is contained in:
@@ -105,8 +105,10 @@ Every variable has exactly one owner, and the owner decides how it is read:
|
||||
`app.get(httpConfig.KEY)` for the pre-init Express layer). Today:
|
||||
`httpConfig` (TRUST_PROXY, HSTS_INCLUDE_SUBDOMAINS, HTTP_KEEP_ALIVE_TIMEOUT_MS),
|
||||
`storageConfig` (TREK_PLACE_PHOTO_DIR), `transitConfig` (TRANSIT_API_URL,
|
||||
for TransitService) and `kitineraryConfig` (KITINERARY_EXTRACTOR_PATH and
|
||||
PATH, for KitineraryExtractorService's binary probe). A module whose provider
|
||||
for TransitService), `kitineraryConfig` (KITINERARY_EXTRACTOR_PATH and
|
||||
PATH, for KitineraryExtractorService's binary probe), `servicesConfig`
|
||||
(TREK_SERVICES and its hosts) and `mailIngestConfig` (MAIL_INGEST_*, for
|
||||
MailIngestSettingsService, each over its stored setting). A module whose provider
|
||||
injects one imports `AppConfigModule`, so it also builds on its own in a test.
|
||||
- **`readEnv()` / `RuntimeEnvService`** (`derive.ts`): everything else, both
|
||||
the runtime-toggled values and the boot-stable ones that code outside a Nest
|
||||
|
||||
@@ -69,6 +69,8 @@ const DEFAULT_SERVICE_HOSTS = ['places.liketrek.com', 'photon.liketrek.com', 'va
|
||||
const DEFAULT_PHOTON_URL = 'https://photon.liketrek.com';
|
||||
/** The TREK services' Valhalla, asked through this server's routing relay. */
|
||||
const DEFAULT_VALHALLA_URL = 'https://valhalla.liketrek.com';
|
||||
/** Signs the Apple Wallet passes of bookings; only liketrek holds the pass certificate. */
|
||||
const DEFAULT_WALLET_PASS_URL = 'https://push.liketrek.com/v1/wallet/pass';
|
||||
|
||||
/**
|
||||
* How this installation identifies itself to the liketrek services. Unset is
|
||||
@@ -84,6 +86,28 @@ export function deriveServices(raw: RawEnv) {
|
||||
hosts: hosts?.length ? hosts : DEFAULT_SERVICE_HOSTS,
|
||||
photonUrl: stripTrailingSlashes(raw.TREK_PHOTON_URL?.trim() || DEFAULT_PHOTON_URL),
|
||||
valhallaUrl: stripTrailingSlashes(raw.TREK_VALHALLA_URL?.trim() || DEFAULT_VALHALLA_URL),
|
||||
walletPassUrl: raw.TREK_WALLET_SIGNER_URL?.trim() || DEFAULT_WALLET_PASS_URL,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* How the booking mail import takes mail in, set in the environment rather
|
||||
* than in the admin dialog: each value wins over its stored setting when it is
|
||||
* non-empty (MailIngestSettingsService applies them). Unset leaves the dialog
|
||||
* in charge, so an install that sets none of them behaves as before.
|
||||
*/
|
||||
export function deriveMailIngest(raw: RawEnv) {
|
||||
const read = (value: string | undefined) => value?.trim() || null;
|
||||
return {
|
||||
transport: read(raw.MAIL_INGEST_TRANSPORT)?.toLowerCase() ?? null,
|
||||
imapHost: read(raw.MAIL_INGEST_IMAP_HOST),
|
||||
imapPort: read(raw.MAIL_INGEST_IMAP_PORT),
|
||||
imapTls: read(raw.MAIL_INGEST_IMAP_TLS)?.toLowerCase() ?? null,
|
||||
imapUser: read(raw.MAIL_INGEST_IMAP_USER),
|
||||
imapPass: read(raw.MAIL_INGEST_IMAP_PASS),
|
||||
imapMailbox: read(raw.MAIL_INGEST_IMAP_MAILBOX),
|
||||
addressTemplate: read(raw.MAIL_INGEST_ADDRESS_TEMPLATE),
|
||||
webhookSecret: read(raw.MAIL_INGEST_WEBHOOK_SECRET),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -94,6 +118,7 @@ export const BOOT_DERIVERS = {
|
||||
transit: deriveTransit,
|
||||
kitinerary: deriveKitinerary,
|
||||
services: deriveServices,
|
||||
mailIngest: deriveMailIngest,
|
||||
} as const;
|
||||
|
||||
export type BootNamespace = keyof typeof BOOT_DERIVERS;
|
||||
|
||||
@@ -112,6 +112,12 @@ export function deriveSession(raw: RawEnv) {
|
||||
};
|
||||
}
|
||||
|
||||
/** A boolean variable as the stored settings spell it, or undefined when unset or not a boolean. */
|
||||
function flagText(raw: string | undefined): 'true' | 'false' | undefined {
|
||||
const value = parseBool(raw);
|
||||
return value === undefined ? undefined : value ? 'true' : 'false';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this instance is centrally administered: somebody other than its
|
||||
* admin user owns the configuration, the credentials and the upgrade schedule.
|
||||
@@ -313,6 +319,12 @@ export function deriveIntegrations(raw: RawEnv) {
|
||||
* request whose prompt plus cap overruns its context (#2677).
|
||||
*/
|
||||
llmMaxOutputTokens: positiveIntOr(raw.LLM_MAX_OUTPUT_TOKENS, 0) || undefined,
|
||||
/**
|
||||
* The operator's word on live flight status, as the admin setting spells it
|
||||
* ('true'/'false'), or undefined when unset or not a boolean: then the admin
|
||||
* switch (`flight_live_enabled`) decides.
|
||||
*/
|
||||
flightLiveEnabled: flagText(raw.FLIGHT_LIVE_ENABLED),
|
||||
// TRANSIT_API_URL, KITINERARY_EXTRACTOR_PATH and PATH are boot-stable and
|
||||
// read only by Nest providers, so the transitConfig and kitineraryConfig
|
||||
// tokens own them (boot-derive.ts).
|
||||
|
||||
@@ -119,6 +119,20 @@ export const envSchema = z.object({
|
||||
SMTP_FROM: anyString,
|
||||
SMTP_SKIP_TLS_VERIFY: boolStr,
|
||||
|
||||
// Booking mail import: each wins over its field in the admin dialog
|
||||
MAIL_INGEST_TRANSPORT: oneOf(['off', 'imap', 'webhook', 'cloud']),
|
||||
MAIL_INGEST_IMAP_HOST: anyString,
|
||||
MAIL_INGEST_IMAP_PORT: integer(1, 65535, 'must be a port number (1-65535)'),
|
||||
MAIL_INGEST_IMAP_TLS: oneOf(['tls', 'starttls']),
|
||||
MAIL_INGEST_IMAP_USER: anyString,
|
||||
MAIL_INGEST_IMAP_PASS: anyString,
|
||||
MAIL_INGEST_IMAP_MAILBOX: anyString,
|
||||
MAIL_INGEST_ADDRESS_TEMPLATE: optionalWith(
|
||||
(v) => v.includes('{token}') && v.includes('@'),
|
||||
'must hold {token} and an @, like trek+{token}@example.com',
|
||||
),
|
||||
MAIL_INGEST_WEBHOOK_SECRET: optionalWith((v) => v.length >= 32, 'must be at least 32 characters'),
|
||||
|
||||
// WebAuthn
|
||||
WEBAUTHN_RP_ID: anyString,
|
||||
WEBAUTHN_ORIGINS: anyString,
|
||||
@@ -199,12 +213,14 @@ export const envSchema = z.object({
|
||||
GOOGLE_LIST_DATA_BASE: url,
|
||||
TREK_PLACES_URL: url,
|
||||
TREK_PLACES_ENABLED: boolStr,
|
||||
FLIGHT_LIVE_ENABLED: boolStr,
|
||||
TREK_PLACES_CONTRIBUTE: oneOf(['off', 'admin']),
|
||||
TREK_SERVICES: oneOf(['auto', 'off']),
|
||||
TREK_SERVICES_KEY: optionalWith(isServiceKeyShape, 'must be a TREK services key (tk1.<kid>.<payload>.<signature>)'),
|
||||
TREK_SERVICES_HOSTS: anyString,
|
||||
TREK_PHOTON_URL: url,
|
||||
TREK_VALHALLA_URL: url,
|
||||
TREK_WALLET_SIGNER_URL: url,
|
||||
PLACES_API_KEY: anyString,
|
||||
AMAP_API_BASE: url,
|
||||
AMAP_API_KEY: anyString,
|
||||
|
||||
@@ -34,6 +34,8 @@ export const SECRET_ENV_KEYS: ReadonlySet<string> = new Set([
|
||||
'CARTO_API_KEY',
|
||||
'DEMO_ADMIN_PASS',
|
||||
'TREK_DB_URL',
|
||||
'MAIL_INGEST_IMAP_PASS',
|
||||
'MAIL_INGEST_WEBHOOK_SECRET',
|
||||
]);
|
||||
|
||||
/** How a variable's value appears in the boot report. */
|
||||
|
||||
Reference in New Issue
Block a user