File tree Expand file tree Collapse file tree 3 files changed +21
-18
lines changed
Expand file tree Collapse file tree 3 files changed +21
-18
lines changed Original file line number Diff line number Diff line change @@ -2,19 +2,23 @@ import instance from './weak_cache.js';
22import isPlainObject from './_/is_plain_object.js' ;
33import { InvalidClientMetadata } from './errors.js' ;
44
5- function addStatic ( metadata ) {
6- const { staticClients } = instance ( this ) ;
7- if ( ! isPlainObject ( metadata ) || ! metadata . client_id ) {
8- throw new InvalidClientMetadata ( 'client_id is mandatory property for statically configured clients' ) ;
9- }
5+ export default function initializeClients ( clients = [ ] ) {
6+ let staticClients ;
107
11- if ( staticClients . has ( metadata . client_id ) ) {
12- throw new InvalidClientMetadata ( 'client_id must be unique amongst statically configured clients' ) ;
13- }
8+ for ( const metadata of clients ) {
9+ if ( ! isPlainObject ( metadata ) || ! metadata . client_id ) {
10+ throw new InvalidClientMetadata ( 'client_id is mandatory property for statically configured clients' ) ;
11+ }
1412
15- staticClients . set ( metadata . client_id , structuredClone ( metadata ) ) ;
16- }
13+ if ( staticClients ?. has ( metadata . client_id ) ) {
14+ throw new InvalidClientMetadata ( 'client_id must be unique amongst statically configured clients' ) ;
15+ }
1716
18- export default function initializeClients ( clients = [ ] ) {
19- clients . map ( addStatic , this ) ;
17+ staticClients ||= new Map ( ) ;
18+ staticClients . set ( metadata . client_id , structuredClone ( metadata ) ) ;
19+ }
20+
21+ if ( staticClients ) {
22+ instance ( this ) . staticClients = staticClients ;
23+ }
2024}
Original file line number Diff line number Diff line change @@ -515,25 +515,25 @@ export default function getClient(provider) {
515515 }
516516
517517 static async find ( id ) {
518- if ( typeof id !== 'string' ) {
518+ if ( typeof id !== 'string' || ! id . length ) {
519519 return undefined ;
520520 }
521521
522522 const { staticClients, dynamicClients } = instance ( provider ) ;
523523
524- if ( staticClients . has ( id ) ) {
525- const cached = staticClients . get ( id ) ;
526-
524+ const cached = staticClients ?. get ( id ) ;
525+ if ( cached ) {
527526 if ( ! ( cached instanceof Client ) ) {
528527 const client = new Client ( cached ) ;
529528 if ( client . sectorIdentifierUri !== undefined ) {
530529 await sectorValidate ( provider , client ) ;
531530 }
532531 Object . defineProperty ( client , 'noManage' , { value : true } ) ;
533532 staticClients . set ( id , client ) ;
533+ return client ;
534534 }
535535
536- return staticClients . get ( id ) ;
536+ return cached ;
537537 }
538538
539539 const properties = await this . adapter . find ( id ) ;
Original file line number Diff line number Diff line change @@ -62,7 +62,6 @@ export class Provider extends Koa {
6262 #exec;
6363
6464 #int = {
65- staticClients : new Map ( ) ,
6665 dynamicClients : new QuickLRU ( { maxSize : 100 } ) ,
6766 } ;
6867
You can’t perform that action at this time.
0 commit comments