@just-every/manager 0.1.48 → 0.1.50

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.
Files changed (2) hide show
  1. package/lib/installer.js +74 -9
  2. package/package.json +1 -1
package/lib/installer.js CHANGED
@@ -107,22 +107,43 @@ function getServicePaths() {
107
107
  }
108
108
 
109
109
  async function fetchLatestVersion() {
110
- const url = `https://api.github.com/repos/${OWNER_REPO}/releases/latest`;
111
- const response = await downloadJson(url);
112
- const tag = (response.tag_name || '').trim();
113
- if (!tag) {
114
- throw new Error('Unable to resolve latest release tag from GitHub.');
110
+ let manifestError;
111
+ try {
112
+ return await fetchLatestVersionFromManifest();
113
+ } catch (error) {
114
+ manifestError = error;
115
+ }
116
+
117
+ try {
118
+ return await fetchLatestVersionFromGitHub();
119
+ } catch (error) {
120
+ const prefix = manifestError ? `Manifest lookup failed: ${manifestError.message || manifestError}` : '';
121
+ const suffix = error ? `GitHub lookup failed: ${error.message || error}` : '';
122
+ const message = [prefix, suffix].filter(Boolean).join(' ');
123
+ throw new Error(message || 'Unable to resolve latest release tag.');
115
124
  }
116
- return tag.replace(/^agent-v/, '').replace(/^v/, '');
117
125
  }
118
126
 
119
- function downloadJson(url) {
127
+ function shouldSendGitHubToken(url) {
128
+ try {
129
+ const parsed = new URL(url);
130
+ return GITHUB_HOSTS.has(parsed.hostname);
131
+ } catch {
132
+ return false;
133
+ }
134
+ }
135
+
136
+ function downloadJson(url, options = {}) {
120
137
  return new Promise((resolve, reject) => {
121
138
  const token = getGitHubToken();
139
+ const accept = options.accept || 'application/vnd.github+json';
140
+ const extraHeaders = options.headers || {};
141
+ const includeToken = token && shouldSendGitHubToken(url);
122
142
  const headers = {
123
143
  'User-Agent': 'justevery-manager-wrapper',
124
- Accept: 'application/vnd.github+json',
125
- ...(token ? { Authorization: `Bearer ${token}` } : {}),
144
+ Accept: accept,
145
+ ...(includeToken ? { Authorization: `Bearer ${token}` } : {}),
146
+ ...extraHeaders,
126
147
  };
127
148
  const req = get(
128
149
  url,
@@ -157,6 +178,50 @@ function downloadJson(url) {
157
178
  });
158
179
  }
159
180
 
181
+ function extractManifestVersion(payload) {
182
+ if (!payload || typeof payload !== 'object') return null;
183
+ const tag =
184
+ (payload.version || payload.tag || payload.tag_name || payload.release_tag || '').toString().trim();
185
+ if (!tag) return null;
186
+ return tag.replace(/^agent-v/, '').replace(/^v/, '');
187
+ }
188
+
189
+ function buildLatestManifestUrls() {
190
+ const overrides = normalizeBaseUrls(process.env.JE_AGENT_RELEASE_MANIFEST_URL || process.env.JE_AGENT_LATEST_URL);
191
+ const apiBase = process.env.JE_MANAGER_API_BASE || process.env.MANAGER_API_BASE || 'https://manager.justevery.com';
192
+ const defaultUrl = `${apiBase.replace(/\/$/, '')}/marketing/agent-release/latest.json`;
193
+ const urls = overrides.length ? overrides : [defaultUrl];
194
+ const fallback = 'https://manager.justevery.com/marketing/agent-release/latest.json';
195
+ if (!urls.includes(fallback)) urls.push(fallback);
196
+ return urls;
197
+ }
198
+
199
+ async function fetchLatestVersionFromManifest() {
200
+ const urls = buildLatestManifestUrls();
201
+ let lastError;
202
+ for (const url of urls) {
203
+ try {
204
+ const payload = await downloadJson(url, { accept: 'application/json' });
205
+ const version = extractManifestVersion(payload);
206
+ if (version) return version;
207
+ lastError = new Error(`Manifest at ${url} missing version.`);
208
+ } catch (error) {
209
+ lastError = error;
210
+ }
211
+ }
212
+ throw lastError || new Error('Unable to resolve latest release manifest.');
213
+ }
214
+
215
+ async function fetchLatestVersionFromGitHub() {
216
+ const url = `https://api.github.com/repos/${OWNER_REPO}/releases/latest`;
217
+ const response = await downloadJson(url);
218
+ const tag = (response.tag_name || '').trim();
219
+ if (!tag) {
220
+ throw new Error('Unable to resolve latest release tag from GitHub.');
221
+ }
222
+ return tag.replace(/^agent-v/, '').replace(/^v/, '');
223
+ }
224
+
160
225
  function normalizeBaseUrls(value) {
161
226
  if (!value) return [];
162
227
  return value
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@just-every/manager",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "description": "Installer wrapper for Every Manager",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",