Moved from CJS to ESM + small improvements like logging

This commit is contained in:
Alan Bridgeman 2026-01-07 15:59:40 -06:00
parent 61df35a271
commit c57160e05d
16 changed files with 512 additions and 488 deletions

View file

@ -1,11 +1,12 @@
import { Application } from 'express';
import { Scopes } from '@BridgemanAccessible/ba-auth';
import Client, { OnAuthCallback } from '@BridgemanAccessible/ba-auth/client';
import { logMessage, LogLevel } from '@BridgemanAccessible/ba-logging';
import { App } from './App';
import { Initializer } from './Initializer';
import { App } from './App.js';
import { Initializer } from './Initializer.js';
import { getValueFromEnvironmentVariable } from './utils/env-vars';
import { getValueFromEnvironmentVariable } from './utils/env-vars.js';
type OAuthAppOptions = {
/** The base URL of the app */
@ -140,25 +141,36 @@ export class OAuthApp extends App {
appAbbrv = getValueFromEnvironmentVariable('APP_ABBRV', { description: 'app abbreviation', blank_allowed: false });
}
console.log(`Attempting to create/register the app:\n\tApp Base URL: ${baseAppUrl}\n\tApp Abbreviation: ${appAbbrv}\n\tApp Name: ${typeof this.appName === 'undefined' ? 'uses APP_NAME environment variable (' + process.env.APP_NAME + ')' : this.appName}\n\tScopes: ${typeof this.scopes === 'undefined' ? 'uses SCOPES environment variable (' + process.env.SCOPES + ')' : this.scopes.join(', ')}`);
logMessage(`Attempting to create/register the app:\n\tApp Base URL: ${baseAppUrl}\n\tApp Abbreviation: ${appAbbrv}\n\tApp Name: ${typeof this.appName === 'undefined' ? 'uses APP_NAME environment variable (' + process.env.APP_NAME + ')' : this.appName}\n\tScopes: ${typeof this.scopes === 'undefined' ? 'uses SCOPES environment variable (' + process.env.SCOPES + ')' : this.scopes.join(', ')}`, LogLevel.DEBUG);
// Because we need this for registration to work properly. It make sense to put it here
app.getInitializer().getRouter().addOutsideFrameworkRoute('/.well-known/jwks.json');
app.getInitializer()
.getRouter()
.addOutsideFrameworkRoute('/.well-known/jwks.json');
const client = await Client.setup(app.getExpressApp(), baseAppUrl, this.onAuth, this.saveSecret, appAbbrv, this.appName, this.scopes, {
contacts: this.contacts,
logo_url: this.logo_url,
tos_url: this.tos_url,
policy_url: this.policy_url,
vault_type: this.vault_type,
auth_default_method: this.auth_default_method,
auth_default_use_JWT: this.auth_default_use_JWT,
auth_default_response_mode: this.auth_default_response_mode,
client_secret: this.client_secret
});
const client = await Client.setup(
app.getExpressApp(),
baseAppUrl,
this.onAuth,
this.saveSecret,
appAbbrv,
this.appName,
this.scopes,
{
contacts: this.contacts,
logo_url: this.logo_url,
tos_url: this.tos_url,
policy_url: this.policy_url,
vault_type: this.vault_type,
auth_default_method: this.auth_default_method,
auth_default_use_JWT: this.auth_default_use_JWT,
auth_default_response_mode: this.auth_default_response_mode,
client_secret: this.client_secret
}
);
client.getSetupRoutes().forEach((route) => {
console.log(`Adding outside framework route: ${route}`);
logMessage(`Adding outside framework route: ${route}`, LogLevel.DEBUG);
app.getInitializer().getRouter().addOutsideFrameworkRoute(route);
});
}
@ -184,9 +196,9 @@ export class OAuthApp extends App {
}
}
catch(err) {
console.error('Error setting up the BA User Auth');
console.error('---------------------------------');
console.error(err);
logMessage('Error setting up the BA User Auth', LogLevel.ERROR);
logMessage('---------------------------------', LogLevel.ERROR);
logMessage(JSON.stringify(err), LogLevel.ERROR);
}
}