Skip to content

Commit e498d98

Browse files
committed
Use @digitalbazaar/lru-memoize@4.
1 parent 36189a6 commit e498d98

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# bedrock-oauth2-client ChangeLog
22

3+
## 7.2.0 - 2024-05-dd
4+
5+
### Changed
6+
- Use `@digitalbazaar/lru-memoize@4`. Existing cache defaults and options
7+
are coerced from previous versions to the new version.
8+
39
## 7.1.0 - 2024-05-09
410

511
### Changed

lib/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright 2021 - 2024 Digital Bazaar, Inc.
2+
* Copyright 2021 - 2025 Digital Bazaar, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,9 +20,9 @@ import {config} from '@bedrock/core';
2020

2121
config['oauth2-client'] = {
2222
accessTokenCache: {
23-
maxSize: 100,
23+
max: 100,
2424
// 5 minutes
25-
maxAge: 5 * 60 * 1000
25+
ttl: 5 * 60 * 1000
2626
},
2727
// time to live - the amount of a time a record will stay in the database
2828
// before it is expired. 2 week expiration in milliseconds.

lib/oauth2-client.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Copyright 2021 - 2024 Digital Bazaar, Inc.
2+
* Copyright 2021 - 2025 Digital Bazaar, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,10 +32,22 @@ const RETRY_MAX_TIMEOUT = 30000;
3232

3333
bedrock.events.on('bedrock.init', async () => {
3434
const cfg = bedrock.config['oauth2-client'];
35-
ACCESS_TOKEN_CACHE = new LruCache({
36-
max: cfg.accessTokenCache.maxSize,
37-
maxAge: cfg.accessTokenCache.maxAge
38-
});
35+
let cacheConfig = cfg.accessTokenCache;
36+
37+
// coerce `maxSize` w/o `sizeCalculation` to `max`
38+
if(cacheConfig.maxSize !== undefined &&
39+
cacheConfig.sizeCalculation === undefined) {
40+
cacheConfig = {...cacheConfig, max: cacheConfig.maxSize};
41+
delete cacheConfig.maxSize;
42+
}
43+
44+
// coerce `maxAge` to `ttl` in `cacheConfig`
45+
if(cacheConfig.maxAge !== undefined) {
46+
cacheConfig = {...cacheConfig, ttl: cacheConfig.maxAge};
47+
delete cacheConfig.maxAge;
48+
}
49+
50+
ACCESS_TOKEN_CACHE = new LruCache(cacheConfig);
3951
});
4052

4153
/**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"homepage": "https://github.com/digitalbazaar/bedrock-oauth2-client",
2727
"dependencies": {
2828
"@digitalbazaar/http-client": "^4.0.0",
29-
"@digitalbazaar/lru-memoize": "^3.0.0",
29+
"@digitalbazaar/lru-memoize": "^4.0.0",
3030
"p-retry": "^6.0.0"
3131
},
3232
"peerDependencies": {

test/mocha/10-api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ describe('oauth2-client', () => {
130130
}
131131
should.exist(err);
132132
should.not.exist(result);
133-
err.message.should.equal('Request failed with status code 403 Forbidden');
133+
err.message.should.equal(
134+
'Request failed with status code 403 Forbidden: ' +
135+
'GET https://localhost:18443/geterrortest');
134136
err.status.should.equal(403);
135137
});
136138
});

0 commit comments

Comments
 (0)