opencode-qwen-cli-auth 2.2.2 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -88,7 +88,7 @@ function toStoredTokenData(data) {
88
88
  : typeof raw.expiry_date === "string"
89
89
  ? Number(raw.expiry_date)
90
90
  : undefined;
91
- const resourceUrl = typeof raw.resource_url === "string" ? raw.resource_url : undefined;
91
+ const resourceUrl = typeof raw.resource_url === "string" ? normalizeResourceUrl(raw.resource_url) : undefined;
92
92
  if (!accessToken || !refreshToken || typeof expiryDate !== "number" || !Number.isFinite(expiryDate) || expiryDate <= 0) {
93
93
  return null;
94
94
  }
@@ -470,7 +470,10 @@ export function loadStoredToken() {
470
470
  logWarn("Invalid token data, re-authentication required");
471
471
  return null;
472
472
  }
473
- const needsRewrite = typeof parsed.expiry_date !== "number" || typeof parsed.token_type !== "string" || typeof parsed.expires === "number";
473
+ const needsRewrite = typeof parsed.expiry_date !== "number" ||
474
+ typeof parsed.token_type !== "string" ||
475
+ typeof parsed.expires === "number" ||
476
+ parsed.resource_url !== normalized.resource_url;
474
477
  if (needsRewrite) {
475
478
  try {
476
479
  writeStoredTokenData(normalized);
@@ -510,7 +513,7 @@ export function saveToken(tokenResult) {
510
513
  refresh_token: tokenResult.refresh,
511
514
  token_type: "Bearer",
512
515
  expiry_date: tokenResult.expires,
513
- resource_url: tokenResult.resourceUrl,
516
+ resource_url: normalizeResourceUrl(tokenResult.resourceUrl),
514
517
  };
515
518
  try {
516
519
  writeStoredTokenData(tokenData);
@@ -551,12 +554,17 @@ export async function getValidToken() {
551
554
  export function getApiBaseUrl(resourceUrl) {
552
555
  if (resourceUrl) {
553
556
  try {
554
- const url = new URL(resourceUrl);
557
+ const normalizedResourceUrl = normalizeResourceUrl(resourceUrl);
558
+ if (!normalizedResourceUrl) {
559
+ logWarn("Invalid resource_url, using default Portal API URL");
560
+ return DEFAULT_QWEN_BASE_URL;
561
+ }
562
+ const url = new URL(normalizedResourceUrl);
555
563
  if (!url.protocol.startsWith("http")) {
556
564
  logWarn("Invalid resource_url protocol, using default Portal API URL");
557
565
  return DEFAULT_QWEN_BASE_URL;
558
566
  }
559
- let baseUrl = resourceUrl.replace(/\/$/, "");
567
+ let baseUrl = normalizedResourceUrl.replace(/\/$/, "");
560
568
  const suffix = "/v1";
561
569
  if (!baseUrl.endsWith(suffix)) {
562
570
  baseUrl = `${baseUrl}${suffix}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-qwen-cli-auth",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "description": "Qwen OAuth authentication plugin for opencode - use your Qwen account instead of API keys",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",