Added some type generics type safety stuff
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 30s

This commit is contained in:
Alan Bridgeman 2026-01-29 11:30:53 -06:00
parent 74316cc41f
commit 223f52b746

View file

@ -98,7 +98,7 @@ type OAuthAppOptions = {
addons?: Addon[], addons?: Addon[],
}; };
export class OAuthApp extends App { export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extends App {
private onAuth: OnAuthCallback; private onAuth: OnAuthCallback;
private saveSecret: (secret: string) => void | Promise<void>; private saveSecret: (secret: string) => void | Promise<void>;
@ -120,7 +120,7 @@ export class OAuthApp extends App {
private subscriptionTiers?: AppSubscriptionTier[]; private subscriptionTiers?: AppSubscriptionTier[];
private addons?: Addon[]; private addons?: Addon[];
private client: Client; private client: Client<TCustomClaims>;
/** /**
* Create a new OAuth app * Create a new OAuth app
@ -197,7 +197,7 @@ export class OAuthApp extends App {
} }
/** Returns the OAuthApp's Client instance (which is useful for managing keys, creating resource request, etc...) */ /** Returns the OAuthApp's Client instance (which is useful for managing keys, creating resource request, etc...) */
getClient(): Client { getClient(): Client<TCustomClaims> {
return this.client; return this.client;
} }
@ -229,7 +229,7 @@ export class OAuthApp extends App {
.getRouter() .getRouter()
.addOutsideFrameworkRoute('/.well-known/jwks.json'); .addOutsideFrameworkRoute('/.well-known/jwks.json');
this.client = await Client.setup<BridgemanAccessibleAppClaims>( this.client = await Client.setup<TCustomClaims>(
app.getExpressApp(), app.getExpressApp(),
baseAppUrl, baseAppUrl,
this.onAuth, this.onAuth,
@ -240,7 +240,7 @@ export class OAuthApp extends App {
subscription_tiers: this.subscriptionTiers, subscription_tiers: this.subscriptionTiers,
addons: this.addons, addons: this.addons,
webhooks: this.webhooks webhooks: this.webhooks
}, } as TCustomClaims,
this.appName, this.appName,
this.scopes, this.scopes,
{ {
@ -271,7 +271,7 @@ export class OAuthApp extends App {
* *
* @param app The Express app object (that is now listening) * @param app The Express app object (that is now listening)
*/ */
private async onStart(app: App, callback?: (app: OAuthApp) => void | Promise<void>) { private async onStart(app: App, callback?: (app: OAuthApp<TCustomClaims>) => void | Promise<void>) {
try { try {
// Setup the OAuth client. // Setup the OAuth client.
// This is done here because we need the client to be serving/listening for requests for the auth library stuff to work // This is done here because we need the client to be serving/listening for requests for the auth library stuff to work
@ -299,7 +299,7 @@ export class OAuthApp extends App {
* And doesn't have to worry about the OAuth details to make this work. * And doesn't have to worry about the OAuth details to make this work.
* Though it does provide tweaking the OAuth details via options provided to the constructor. * Though it does provide tweaking the OAuth details via options provided to the constructor.
*/ */
async run<T extends Initializer>(initializer?: T, callback?: (app: OAuthApp) => void | Promise<void>) { async run<T extends Initializer>(initializer?: T, callback?: (app: OAuthApp<TCustomClaims>) => void | Promise<void>) {
await super.run(initializer, async (app: App) => this.onStart(app, callback)); await super.run(initializer, async (app: App) => this.onStart(app, callback));
} }
} }