Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

## [Unreleased]

## [0.10.1] - 2026-04-05

### 2026-04-05
- **Fix**: token と apiKey が config に共存する場合、`canRefresh()` が apiKey の存在でリフレッシュをブロックし、JWT 期限切れ後にセッションが復旧不能になる問題を修正 (#98)
- **Feat**: リクエスト前に JWT の `exp` を確認し、期限切れ/期限間近なら事前にリフレッシュするプロアクティブ・トークンリフレッシュを追加 (#98)

## [0.10.0] - 2026-04-03

### 2026-04-03
Expand Down Expand Up @@ -176,7 +182,8 @@
### 2026-02-26
- **Docs**: README にインストール手順・使い方・コマンドリファレンスを追加 (#1)

[Unreleased]: https://github.com/geolonia/geonicdb-cli/compare/v0.10.0...HEAD
[Unreleased]: https://github.com/geolonia/geonicdb-cli/compare/v0.10.1...HEAD
[0.10.1]: https://github.com/geolonia/geonicdb-cli/compare/v0.10.0...v0.10.1
[0.10.0]: https://github.com/geolonia/geonicdb-cli/compare/v0.9.0...v0.10.0
[0.9.0]: https://github.com/geolonia/geonicdb-cli/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/geolonia/geonicdb-cli/compare/v0.7.0...v0.8.0
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@geolonia/geonicdb-cli",
"version": "0.10.0",
"version": "0.10.1",
"description": "A CLI client for the GeonicDB",
"type": "module",
"bin": {
Expand Down
17 changes: 16 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ClientOptions, ClientResponse, NgsiError } from "./types.js";
import { clientCredentialsGrant } from "./oauth.js";
import { getTokenStatus } from "./token.js";

export class DryRunSignal extends Error {
constructor() {
Expand Down Expand Up @@ -163,7 +164,19 @@ export class GdbClient {
}

private canRefresh(): boolean {
return (!!this.refreshToken || (!!this.clientId && !!this.clientSecret)) && !this.apiKey;
if (!this.refreshToken && !(this.clientId && this.clientSecret)) return false;
// When authenticating solely via apiKey (no token), token refresh is unnecessary
if (!this.token && this.apiKey) return false;
return true;
}

/** Proactively refresh the token before making a request if it is expired or about to expire. */
private async proactiveRefresh(): Promise<void> {
if (!this.token || !this.canRefresh()) return;
const status = getTokenStatus(this.token);
if (status.isExpired || status.isExpiringSoon) {
await this.performTokenRefresh();
}
}

/** Check whether an error indicates an authentication/token problem that may be resolved by refreshing. */
Expand Down Expand Up @@ -341,6 +354,7 @@ export class GdbClient {
headers?: Record<string, string>;
},
): Promise<ClientResponse<T>> {
await this.proactiveRefresh();
try {
return await this.executeRequest<T>(method, path, options);
} catch (err) {
Expand Down Expand Up @@ -404,6 +418,7 @@ export class GdbClient {
skipTenantHeader?: boolean;
},
): Promise<ClientResponse<T>> {
await this.proactiveRefresh();
try {
return await this.executeRawRequest<T>(method, path, options);
} catch (err) {
Expand Down
Loading
Loading