@commonlyai/cli 0.1.23 → 0.1.24
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.
- package/package.json +1 -1
- package/src/lib/config.js +13 -4
package/package.json
CHANGED
package/src/lib/config.js
CHANGED
|
@@ -67,10 +67,19 @@ export const resolveInstance = (identifier = null) => {
|
|
|
67
67
|
const looksLikeUrl = /^https?:\/\//i.test(identifier);
|
|
68
68
|
if (looksLikeUrl) {
|
|
69
69
|
const normalized = normalizeUrl(identifier);
|
|
70
|
-
const
|
|
71
|
-
.
|
|
72
|
-
if (
|
|
73
|
-
|
|
70
|
+
const matches = Object.entries(config.instances)
|
|
71
|
+
.filter(([, v]) => normalizeUrl(v.url) === normalized);
|
|
72
|
+
if (matches.length > 0) {
|
|
73
|
+
// Several keys can share one URL (`dev` and `default` both pointing at
|
|
74
|
+
// api.commonly.me after a re-login under a new key). The first entry in
|
|
75
|
+
// file order is then whichever was saved FIRST — the stale one — and
|
|
76
|
+
// every command that resolves by the token file's instanceUrl
|
|
77
|
+
// (detach, wake) got a 401 from a token the user had already replaced.
|
|
78
|
+
// Prefer the active instance, then the most recently saved.
|
|
79
|
+
const active = matches.find(([key]) => key === config.active);
|
|
80
|
+
const [key, value] = active || matches
|
|
81
|
+
.slice()
|
|
82
|
+
.sort(([, a], [, b]) => String(b.savedAt || '').localeCompare(String(a.savedAt || '')))[0];
|
|
74
83
|
return { key, ...value };
|
|
75
84
|
}
|
|
76
85
|
// Unknown URL — still usable for bootstrapping. Preserve the caller's
|