Changes so that I don't have to change the OAuthApp class if I change the custom claims next time (the types should just work automatically)
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 33s
All checks were successful
Publish to Private NPM Registry / publish (push) Successful in 33s
This commit is contained in:
parent
7d2397966f
commit
90168f0858
1 changed files with 33 additions and 29 deletions
|
|
@ -14,7 +14,7 @@ import type { AppSubscriptionTier } from './types/AppSubscriptionTier.js';
|
|||
import type { Addon } from './types/addons/Addon.js';
|
||||
import type { Webhook } from './types/Webhook.js';
|
||||
|
||||
type OAuthAppOptions = {
|
||||
interface BasicOAuthAppOptions {
|
||||
// ------------------
|
||||
// Basic app metadata
|
||||
// ------------------
|
||||
|
|
@ -23,7 +23,7 @@ type OAuthAppOptions = {
|
|||
baseAppUrl?: URL,
|
||||
|
||||
/** The abbreviation of the app */
|
||||
appAbbrv?: string,
|
||||
//appAbbrv?: string,
|
||||
|
||||
/** The (potentially localized) name of the app */
|
||||
appName?: string | {
|
||||
|
|
@ -82,27 +82,30 @@ type OAuthAppOptions = {
|
|||
// ------------------------------
|
||||
|
||||
/** The webhooks supported by the app */
|
||||
webhooks?: Webhook[],
|
||||
//webhooks?: Webhook[],
|
||||
|
||||
// ------------------------------------------
|
||||
// Purchasable Stuff (Subscriptions + Addons)
|
||||
// ------------------------------------------
|
||||
|
||||
/** If a subscription is required */
|
||||
subscriptionRequired?: boolean,
|
||||
//subscriptionRequired?: boolean,
|
||||
|
||||
/** The subscription tiers available for the app */
|
||||
subscriptionTiers?: AppSubscriptionTier[],
|
||||
//subscriptionTiers?: AppSubscriptionTier[],
|
||||
|
||||
/** Addons offered by the app */
|
||||
addons?: Addon[],
|
||||
//addons?: Addon[],
|
||||
};
|
||||
|
||||
type OAuthAppOptions<T extends BridgemanAccessibleAppClaims> = T & BasicOAuthAppOptions;
|
||||
|
||||
export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extends App {
|
||||
private onAuth: OnAuthCallback;
|
||||
private saveSecret: (secret: string) => void | Promise<void>;
|
||||
|
||||
private baseAppUrl?: URL;
|
||||
private options: OAuthAppOptions<TCustomClaims>;
|
||||
/*private baseAppUrl?: URL;
|
||||
private appAbbrv?: string;
|
||||
private appName?: string | { [language: string]: string };
|
||||
private contacts?: string[];
|
||||
|
|
@ -118,7 +121,7 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extend
|
|||
private webhooks?: Webhook[];
|
||||
private subscriptionRequired?: boolean;
|
||||
private subscriptionTiers?: AppSubscriptionTier[];
|
||||
private addons?: Addon[];
|
||||
private addons?: Addon[];*/
|
||||
|
||||
private client: Client<TCustomClaims>;
|
||||
|
||||
|
|
@ -169,13 +172,14 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extend
|
|||
constructor(
|
||||
onAuth: OnAuthCallback,
|
||||
saveSecret: (secret: string) => void | Promise<void>,
|
||||
options?: OAuthAppOptions
|
||||
options?: OAuthAppOptions<TCustomClaims>
|
||||
) {
|
||||
super();
|
||||
this.onAuth = onAuth;
|
||||
this.saveSecret = saveSecret;
|
||||
this.options = options ?? {} as OAuthAppOptions<TCustomClaims>;
|
||||
|
||||
if(typeof options !== 'undefined') {
|
||||
/*if(typeof options !== 'undefined') {
|
||||
this.baseAppUrl = options.baseAppUrl;
|
||||
this.appAbbrv = options.appAbbrv;
|
||||
this.appName = options.appName;
|
||||
|
|
@ -193,7 +197,7 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extend
|
|||
this.subscriptionRequired = options.subscriptionRequired;
|
||||
this.subscriptionTiers = options.subscriptionTiers;
|
||||
this.addons = options.addons;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/** Returns the OAuthApp's Client instance (which is useful for managing keys, creating resource request, etc...) */
|
||||
|
|
@ -211,18 +215,18 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extend
|
|||
*/
|
||||
private async setupOAuthClient(app: App) {
|
||||
// If the base URL of the app isn't provided, get it from the environment variable
|
||||
let baseAppUrl = this.baseAppUrl;
|
||||
let baseAppUrl = this.options.baseAppUrl;
|
||||
if(typeof baseAppUrl === 'undefined') {
|
||||
baseAppUrl = new URL(getValueFromEnvironmentVariable('BASE_APP_URL', { description: 'app\'s base URL', blank_allowed: false }));
|
||||
}
|
||||
|
||||
// The app abbreviation (used for user properties associated with the app)
|
||||
let appAbbrv = this.appAbbrv;
|
||||
let appAbbrv = this.options.client_abbreviation;
|
||||
if(typeof appAbbrv === 'undefined') {
|
||||
appAbbrv = getValueFromEnvironmentVariable('APP_ABBRV', { description: 'app abbreviation', blank_allowed: false });
|
||||
}
|
||||
|
||||
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);
|
||||
logMessage(`Attempting to create/register the app:\n\tApp Base URL: ${baseAppUrl}\n\tApp Abbreviation: ${appAbbrv}\n\tApp Name: ${typeof this.options.appName === 'undefined' ? 'uses APP_NAME environment variable (' + process.env.APP_NAME + ')' : this.options.appName}\n\tScopes: ${typeof this.options.scopes === 'undefined' ? 'uses SCOPES environment variable (' + process.env.SCOPES + ')' : this.options.scopes.join(', ')}`, LogLevel.DEBUG);
|
||||
|
||||
// Because we need this for registration to work properly. It make sense to put it here
|
||||
app.getInitializer()
|
||||
|
|
@ -236,23 +240,23 @@ export class OAuthApp<TCustomClaims extends BridgemanAccessibleAppClaims> extend
|
|||
this.saveSecret,
|
||||
{
|
||||
client_abbreviation: appAbbrv,
|
||||
subscription_required: this.subscriptionRequired ?? false,
|
||||
subscription_tiers: this.subscriptionTiers,
|
||||
addons: this.addons,
|
||||
webhooks: this.webhooks
|
||||
subscription_required: this.options.subscriptionRequired ?? false,
|
||||
subscription_tiers: this.options.subscriptionTiers,
|
||||
addons: this.options.addons,
|
||||
webhooks: this.options.webhooks
|
||||
} as TCustomClaims,
|
||||
this.appName,
|
||||
this.scopes,
|
||||
this.options.appName,
|
||||
this.options.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
|
||||
contacts: this.options.contacts,
|
||||
logo_url: this.options.logo_url,
|
||||
tos_url: this.options.tos_url,
|
||||
policy_url: this.options.policy_url,
|
||||
vault_type: this.options.vault_type,
|
||||
auth_default_method: this.options.auth_default_method,
|
||||
auth_default_use_JWT: this.options.auth_default_use_JWT,
|
||||
auth_default_response_mode: this.options.auth_default_response_mode,
|
||||
client_secret: this.options.client_secret
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue