@@ -32,6 +32,25 @@ function removeTrailingSlash(str) {
3232 return str ;
3333}
3434
35+ // List of config keys that can be async (functions or promises)
36+ const asyncKeys = [ 'publicServerURL' ] ;
37+
38+ /**
39+ * Helper function to resolve an async config value.
40+ * If the value is a function, it executes it and returns the result.
41+ * If the value is a promise, it awaits it and returns the result.
42+ * Otherwise, it returns the raw value.
43+ */
44+ async function resolveAsyncValue ( value ) {
45+ if ( typeof value === 'function' ) {
46+ return await value ( ) ;
47+ }
48+ if ( value && typeof value . then === 'function' ) {
49+ return await value ;
50+ }
51+ return value ;
52+ }
53+
3554export class Config {
3655 static get ( applicationId : string , mount : string ) {
3756 const cacheInfo = AppCache . get ( applicationId ) ;
@@ -53,14 +72,28 @@ export class Config {
5372 config
5473 ) ;
5574 config . version = version ;
75+
76+ // Transform async keys: store original in _[key]
77+ asyncKeys . forEach ( key => {
78+ if ( config [ key ] !== undefined && ( typeof config [ key ] === 'function' || ( config [ key ] && typeof config [ key ] . then === 'function' ) ) ) {
79+ config [ `_${ key } ` ] = config [ key ] ;
80+ // Will be resolved in middleware
81+ delete config [ key ] ;
82+ }
83+ } ) ;
84+
5685 return config ;
5786 }
5887
59- async getPublicServerURL ( ) {
60- if ( typeof this . publicServerURL === 'function' ) {
61- return await this . publicServerURL ( ) ;
62- }
63- return this . publicServerURL ;
88+ async loadKeys ( ) {
89+ await Promise . all (
90+ asyncKeys . map ( async key => {
91+ if ( this [ `_${ key } ` ] !== undefined ) {
92+ this [ key ] = await resolveAsyncValue ( this [ `_${ key } ` ] ) ;
93+ }
94+ } )
95+ ) ;
96+ AppCache . put ( this . appId , this ) ;
6497 }
6598
6699 static put ( serverConfiguration ) {
@@ -692,64 +725,55 @@ export class Config {
692725 }
693726 }
694727
695- async invalidLinkURL ( ) {
696- const publicServerURL = await this . getPublicServerURL ( ) ;
697- return this . customPages . invalidLink || `${ publicServerURL } /apps/invalid_link.html` ;
728+ get invalidLinkURL ( ) {
729+ return this . customPages . invalidLink || `${ this . publicServerURL } /apps/invalid_link.html` ;
698730 }
699731
700- async invalidVerificationLinkURL ( ) {
701- const publicServerURL = await this . getPublicServerURL ( ) ;
732+ get invalidVerificationLinkURL ( ) {
702733 return (
703734 this . customPages . invalidVerificationLink ||
704- `${ publicServerURL } /apps/invalid_verification_link.html`
735+ `${ this . publicServerURL } /apps/invalid_verification_link.html`
705736 ) ;
706737 }
707738
708- async linkSendSuccessURL ( ) {
709- const publicServerURL = await this . getPublicServerURL ( ) ;
739+ get linkSendSuccessURL ( ) {
710740 return (
711- this . customPages . linkSendSuccess || `${ publicServerURL } /apps/link_send_success.html`
741+ this . customPages . linkSendSuccess || `${ this . publicServerURL } /apps/link_send_success.html`
712742 ) ;
713743 }
714744
715- async linkSendFailURL ( ) {
716- const publicServerURL = await this . getPublicServerURL ( ) ;
717- return this . customPages . linkSendFail || `${ publicServerURL } /apps/link_send_fail.html` ;
745+ get linkSendFailURL ( ) {
746+ return this . customPages . linkSendFail || `${ this . publicServerURL } /apps/link_send_fail.html` ;
718747 }
719748
720- async verifyEmailSuccessURL ( ) {
721- const publicServerURL = await this . getPublicServerURL ( ) ;
749+ get verifyEmailSuccessURL ( ) {
722750 return (
723751 this . customPages . verifyEmailSuccess ||
724- `${ publicServerURL } /apps/verify_email_success.html`
752+ `${ this . publicServerURL } /apps/verify_email_success.html`
725753 ) ;
726754 }
727755
728- async choosePasswordURL ( ) {
729- const publicServerURL = await this . getPublicServerURL ( ) ;
730- return this . customPages . choosePassword || `${ publicServerURL } /apps/choose_password` ;
756+ get choosePasswordURL ( ) {
757+ return this . customPages . choosePassword || `${ this . publicServerURL } /apps/choose_password` ;
731758 }
732759
733- async requestResetPasswordURL ( ) {
734- const publicServerURL = await this . getPublicServerURL ( ) ;
735- return `${ publicServerURL } /${ this . pagesEndpoint } /${ this . applicationId } /request_password_reset` ;
760+ get requestResetPasswordURL ( ) {
761+ return `${ this . publicServerURL } /${ this . pagesEndpoint } /${ this . applicationId } /request_password_reset` ;
736762 }
737763
738- async passwordResetSuccessURL ( ) {
739- const publicServerURL = await this . getPublicServerURL ( ) ;
764+ get passwordResetSuccessURL ( ) {
740765 return (
741766 this . customPages . passwordResetSuccess ||
742- `${ publicServerURL } /apps/password_reset_success.html`
767+ `${ this . publicServerURL } /apps/password_reset_success.html`
743768 ) ;
744769 }
745770
746771 get parseFrameURL ( ) {
747772 return this . customPages . parseFrameURL ;
748773 }
749774
750- async verifyEmailURL ( ) {
751- const publicServerURL = await this . getPublicServerURL ( ) ;
752- return `${ publicServerURL } /${ this . pagesEndpoint } /${ this . applicationId } /verify_email` ;
775+ get verifyEmailURL ( ) {
776+ return `${ this . publicServerURL } /${ this . pagesEndpoint } /${ this . applicationId } /verify_email` ;
753777 }
754778
755779 async loadMasterKey ( ) {
0 commit comments