featurely-site-manager 1.1.2 → 1.1.4

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/dist/index.js CHANGED
@@ -280,7 +280,22 @@ var _SiteManager = class _SiteManager {
280
280
  }
281
281
  );
282
282
  if (!response.ok) {
283
- throw new Error(`Failed to fetch site configuration: ${response.statusText}`);
283
+ const errorData = await response.json().catch(() => ({}));
284
+ const message = errorData.error || response.statusText;
285
+ if (response.status === 401) {
286
+ console.error(
287
+ `[Featurely] Invalid or missing API key. ${message}
288
+ \u2192 Check your API key at https://www.featurely.no/dashboard/settings`
289
+ );
290
+ this.stopPolling();
291
+ } else if (response.status === 403) {
292
+ console.error(
293
+ `[Featurely] Permission denied. ${message}
294
+ \u2192 Ensure your API key has the required permissions at https://www.featurely.no/dashboard/settings`
295
+ );
296
+ this.stopPolling();
297
+ }
298
+ throw new Error(`Failed to fetch site configuration: ${message}`);
284
299
  }
285
300
  const newConfig = await response.json();
286
301
  const configChanged = JSON.stringify(newConfig) !== JSON.stringify(this.siteConfig);
@@ -306,13 +321,22 @@ var _SiteManager = class _SiteManager {
306
321
  } catch (error) {
307
322
  this.consecutiveFetchFailures++;
308
323
  if (this.consecutiveFetchFailures <= _SiteManager.MAX_CONSECUTIVE_FAILURES) {
309
- console.error("Featurely Site Manager: Failed to fetch configuration", error);
324
+ const isNetworkError = error instanceof TypeError && (error.message.includes("NetworkError") || error.message.includes("Failed to fetch") || error.message.includes("fetch"));
325
+ if (isNetworkError) {
326
+ console.error(
327
+ `[Featurely] Network error \u2014 request to Featurely was blocked.
328
+ \u2192 If your site has a Content-Security-Policy, add 'https://www.featurely.no' to the connect-src directive.
329
+ Example: connect-src 'self' https://www.featurely.no ...`
330
+ );
331
+ } else {
332
+ console.error("Featurely Site Manager: Failed to fetch configuration", error);
333
+ }
310
334
  if (this.config.onError && error instanceof Error) {
311
335
  this.config.onError(error);
312
336
  }
313
337
  } else if (this.consecutiveFetchFailures === _SiteManager.MAX_CONSECUTIVE_FAILURES + 1) {
314
338
  console.error(
315
- `Featurely Site Manager: Silencing repeated fetch errors after ${_SiteManager.MAX_CONSECUTIVE_FAILURES} failures. Check your apiUrl configuration.`
339
+ `Featurely Site Manager: Silencing repeated fetch errors after ${_SiteManager.MAX_CONSECUTIVE_FAILURES} failures. Check your apiUrl and Content-Security-Policy configuration.`
316
340
  );
317
341
  }
318
342
  }
@@ -365,7 +389,8 @@ var _SiteManager = class _SiteManager {
365
389
  userId: this.config.userId,
366
390
  sessionId: this.sessionId,
367
391
  userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
368
- platform: typeof navigator !== "undefined" ? navigator.platform : void 0
392
+ platform: typeof navigator !== "undefined" ? navigator.platform : void 0,
393
+ appVersion: this.config.appVersion
369
394
  })
370
395
  }
371
396
  );
package/dist/index.mjs CHANGED
@@ -245,7 +245,22 @@ var _SiteManager = class _SiteManager {
245
245
  }
246
246
  );
247
247
  if (!response.ok) {
248
- throw new Error(`Failed to fetch site configuration: ${response.statusText}`);
248
+ const errorData = await response.json().catch(() => ({}));
249
+ const message = errorData.error || response.statusText;
250
+ if (response.status === 401) {
251
+ console.error(
252
+ `[Featurely] Invalid or missing API key. ${message}
253
+ \u2192 Check your API key at https://www.featurely.no/dashboard/settings`
254
+ );
255
+ this.stopPolling();
256
+ } else if (response.status === 403) {
257
+ console.error(
258
+ `[Featurely] Permission denied. ${message}
259
+ \u2192 Ensure your API key has the required permissions at https://www.featurely.no/dashboard/settings`
260
+ );
261
+ this.stopPolling();
262
+ }
263
+ throw new Error(`Failed to fetch site configuration: ${message}`);
249
264
  }
250
265
  const newConfig = await response.json();
251
266
  const configChanged = JSON.stringify(newConfig) !== JSON.stringify(this.siteConfig);
@@ -271,13 +286,22 @@ var _SiteManager = class _SiteManager {
271
286
  } catch (error) {
272
287
  this.consecutiveFetchFailures++;
273
288
  if (this.consecutiveFetchFailures <= _SiteManager.MAX_CONSECUTIVE_FAILURES) {
274
- console.error("Featurely Site Manager: Failed to fetch configuration", error);
289
+ const isNetworkError = error instanceof TypeError && (error.message.includes("NetworkError") || error.message.includes("Failed to fetch") || error.message.includes("fetch"));
290
+ if (isNetworkError) {
291
+ console.error(
292
+ `[Featurely] Network error \u2014 request to Featurely was blocked.
293
+ \u2192 If your site has a Content-Security-Policy, add 'https://www.featurely.no' to the connect-src directive.
294
+ Example: connect-src 'self' https://www.featurely.no ...`
295
+ );
296
+ } else {
297
+ console.error("Featurely Site Manager: Failed to fetch configuration", error);
298
+ }
275
299
  if (this.config.onError && error instanceof Error) {
276
300
  this.config.onError(error);
277
301
  }
278
302
  } else if (this.consecutiveFetchFailures === _SiteManager.MAX_CONSECUTIVE_FAILURES + 1) {
279
303
  console.error(
280
- `Featurely Site Manager: Silencing repeated fetch errors after ${_SiteManager.MAX_CONSECUTIVE_FAILURES} failures. Check your apiUrl configuration.`
304
+ `Featurely Site Manager: Silencing repeated fetch errors after ${_SiteManager.MAX_CONSECUTIVE_FAILURES} failures. Check your apiUrl and Content-Security-Policy configuration.`
281
305
  );
282
306
  }
283
307
  }
@@ -330,7 +354,8 @@ var _SiteManager = class _SiteManager {
330
354
  userId: this.config.userId,
331
355
  sessionId: this.sessionId,
332
356
  userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
333
- platform: typeof navigator !== "undefined" ? navigator.platform : void 0
357
+ platform: typeof navigator !== "undefined" ? navigator.platform : void 0,
358
+ appVersion: this.config.appVersion
334
359
  })
335
360
  }
336
361
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "featurely-site-manager",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Complete site management SDK for maintenance mode, status messages, feature flags, version checking, and analytics",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",