featurely-site-manager 1.1.14 → 1.1.17
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/README.md +72 -0
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +20 -10
- package/dist/index.mjs +20 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,25 @@ siteManager.init();
|
|
|
23
23
|
|
|
24
24
|
## ✨ Features
|
|
25
25
|
|
|
26
|
+
### 🐛 Debug Overlay
|
|
27
|
+
|
|
28
|
+
- Floating debug panel injected into your site when debug mode is enabled
|
|
29
|
+
- **SDK tab** — live state: environment, maintenance status, active messages, feature flags
|
|
30
|
+
- **Logs tab** — real-time log stream with level-coloured rows (info / warn / error), error count badge, Clear button
|
|
31
|
+
- **Network tab** — config fetch history with status codes and timestamps
|
|
32
|
+
- **Events tab** — all analytics events queued or sent
|
|
33
|
+
- **Test tab** — send test analytics events, check feature flags by key, trigger test errors/bugs, flush the analytics queue, refresh config
|
|
34
|
+
- Intercepts `console.error` and `console.warn` — captured errors appear in the Logs tab
|
|
35
|
+
- Global `window.onerror` and `unhandledrejection` listeners capture uncaught errors
|
|
36
|
+
- Verbose lifecycle logging: init steps, config delta on each poll, analytics flush counts, flag lookups, maintenance state changes
|
|
37
|
+
|
|
38
|
+
### 🌍 Environments
|
|
39
|
+
|
|
40
|
+
- Per-environment config (maintenance, debug, messages) matched by URL
|
|
41
|
+
- SDK auto-detects the current environment from `window.location.hostname`
|
|
42
|
+
- Configure environment URLs in your Featurely dashboard → Environments
|
|
43
|
+
- Enable/disable debug mode globally or per-environment
|
|
44
|
+
|
|
26
45
|
### 🔧 Maintenance Mode
|
|
27
46
|
|
|
28
47
|
- **Default** or **custom** maintenance pages
|
|
@@ -245,6 +264,58 @@ When `enableAnalytics` is `true` (default), the SDK automatically tracks:
|
|
|
245
264
|
|
|
246
265
|
Page tracking is SPA-compatible — it patches `history.pushState` and `history.replaceState` and listens to `popstate` so navigations in React, Next.js, Vue, and similar frameworks are captured automatically.
|
|
247
266
|
|
|
267
|
+
### Debug Overlay
|
|
268
|
+
|
|
269
|
+
Enable the debug overlay from your Featurely dashboard (Maintenance → Debug Overlay) or pass `debugMode: true` directly. When active, a `[FT]` button appears in the bottom-right corner of your site.
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
const manager = new SiteManager({
|
|
273
|
+
apiKey: "ft_live_your_api_key",
|
|
274
|
+
projectId: "proj_your_project_id",
|
|
275
|
+
// debugMode is read from the server config — no client code needed.
|
|
276
|
+
// You can also force it on locally:
|
|
277
|
+
// debugMode: true,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
manager.init();
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
The overlay panel has five tabs:
|
|
284
|
+
|
|
285
|
+
| Tab | Contents |
|
|
286
|
+
| --- | --- |
|
|
287
|
+
| **SDK** | Environment, maintenance status, active messages, feature flag count |
|
|
288
|
+
| **Logs** | Real-time log stream (info / warn / error); error badge on tab; Clear button |
|
|
289
|
+
| **Network** | Config fetch log with status codes and timestamps |
|
|
290
|
+
| **Events** | Analytics events queued/sent |
|
|
291
|
+
| **Test** | Buttons to test analytics, errors, bugs, feature flags, flush, and refresh |
|
|
292
|
+
|
|
293
|
+
#### Test Tab Actions
|
|
294
|
+
|
|
295
|
+
- **Send test event** — fires a `test_event` analytics event
|
|
296
|
+
- **Flush queue** — immediately sends all queued analytics events
|
|
297
|
+
- **Check flag** — enter a flag key to see its current enabled state
|
|
298
|
+
- **Trigger test error** — throws a JS error captured in the Logs tab
|
|
299
|
+
- **Trigger test bug** — fires a `test_bug_report` analytics event
|
|
300
|
+
- **Refresh config** — manually polls the Featurely API
|
|
301
|
+
|
|
302
|
+
### Environment-Aware Setup
|
|
303
|
+
|
|
304
|
+
When you have multiple environments (production, staging, localhost) configured in your Featurely dashboard, the SDK automatically detects the current environment from `window.location.hostname` — no manual configuration needed.
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
const manager = new SiteManager({
|
|
308
|
+
apiKey: "ft_live_your_api_key",
|
|
309
|
+
projectId: "proj_your_project_id",
|
|
310
|
+
// Environment is auto-detected from window.location.hostname
|
|
311
|
+
// matching the URL patterns set in your Featurely dashboard.
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
manager.init();
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
Configure environment URLs in your Featurely dashboard → **Environments**. The SDK matches the current `hostname` against each environment's configured URL. The matching environment's settings (maintenance, debug, messages) take effect.
|
|
318
|
+
|
|
248
319
|
### Custom Poll Interval
|
|
249
320
|
|
|
250
321
|
```typescript
|
|
@@ -283,6 +354,7 @@ manager.init();
|
|
|
283
354
|
| `onUpdateAvailable` | `function` | ❌ | - | Callback when update is available |
|
|
284
355
|
| `onUpdateRequired` | `function` | ❌ | - | Callback when update is required (forced) |
|
|
285
356
|
| `onError` | `function` | ❌ | - | Error callback |
|
|
357
|
+
| `debugMode` | `boolean` | ❌ | `false` | Force-enable debug overlay locally |
|
|
286
358
|
|
|
287
359
|
## 🎯 API Methods
|
|
288
360
|
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -98,8 +98,7 @@ var _SiteManager = class _SiteManager {
|
|
|
98
98
|
// 1 hour
|
|
99
99
|
onUpdateAvailable: config.onUpdateAvailable,
|
|
100
100
|
onUpdateRequired: config.onUpdateRequired,
|
|
101
|
-
debugMode: (_f = config.debugMode) != null ? _f : false
|
|
102
|
-
environment: config.environment
|
|
101
|
+
debugMode: (_f = config.debugMode) != null ? _f : false
|
|
103
102
|
};
|
|
104
103
|
this.loadDismissedMessages();
|
|
105
104
|
}
|
|
@@ -107,7 +106,6 @@ var _SiteManager = class _SiteManager {
|
|
|
107
106
|
* Initialize and start the site manager
|
|
108
107
|
*/
|
|
109
108
|
async init() {
|
|
110
|
-
var _a;
|
|
111
109
|
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
112
110
|
console.warn(
|
|
113
111
|
"Featurely Site Manager: Can only be initialized in a browser environment"
|
|
@@ -117,7 +115,7 @@ var _SiteManager = class _SiteManager {
|
|
|
117
115
|
if (this.config.debugMode) {
|
|
118
116
|
this.setupDebugOverlay();
|
|
119
117
|
}
|
|
120
|
-
this.debugLog("info", `[init] v1.1.
|
|
118
|
+
this.debugLog("info", `[init] v1.1.16 | project: ${this.config.projectId} | hostname: ${typeof window !== "undefined" ? window.location.hostname : "\u2014"}`);
|
|
121
119
|
this.debugLog("info", `[init] analytics: ${this.config.enableAnalytics ? "on" : "off"} | poll: ${this.config.pollInterval}ms | debug: ${this.config.debugMode ? "on" : "off"}`);
|
|
122
120
|
if (this.config.enableAnalytics) {
|
|
123
121
|
this.debugLog("info", "[init] starting analytics + page tracking");
|
|
@@ -366,10 +364,12 @@ var _SiteManager = class _SiteManager {
|
|
|
366
364
|
if (newConfig.debugMode === true && !this.debugOverlayEl) {
|
|
367
365
|
this.setupDebugOverlay();
|
|
368
366
|
}
|
|
369
|
-
if (!this.debugOverlayEl
|
|
367
|
+
if (!this.debugOverlayEl) {
|
|
368
|
+
const hostname = typeof window !== "undefined" ? window.location.hostname : "";
|
|
370
369
|
const envs = newConfig.environments;
|
|
371
|
-
const
|
|
372
|
-
if ((
|
|
370
|
+
const matchedEnv = hostname ? envs == null ? void 0 : envs.find((e) => typeof e.url === "string" && e.url !== "" && e.url === hostname) : void 0;
|
|
371
|
+
if ((matchedEnv == null ? void 0 : matchedEnv.debugEnabled) === true) {
|
|
372
|
+
this.debugLog("info", `[env] matched environment "${matchedEnv.name}" (${hostname})`);
|
|
373
373
|
this.setupDebugOverlay();
|
|
374
374
|
}
|
|
375
375
|
}
|
|
@@ -629,9 +629,9 @@ var _SiteManager = class _SiteManager {
|
|
|
629
629
|
const flagCount = (_c = (_b = sc == null ? void 0 : sc.featureFlags) == null ? void 0 : _b.length) != null ? _c : 0;
|
|
630
630
|
const msgCount = (_e = (_d = sc == null ? void 0 : sc.messages) == null ? void 0 : _d.length) != null ? _e : 0;
|
|
631
631
|
content = `
|
|
632
|
-
${row("SDK Version", "1.1.
|
|
632
|
+
${row("SDK Version", "1.1.16")}
|
|
633
633
|
${row("Project", cfg.projectId)}
|
|
634
|
-
${row("
|
|
634
|
+
${row("Hostname", typeof window !== "undefined" ? window.location.hostname : "\u2014")}
|
|
635
635
|
${row("API URL", cfg.apiUrl)}
|
|
636
636
|
${row("Maintenance", maintenance)}
|
|
637
637
|
${row("Feature Flags", `${flagCount} active`)}
|
|
@@ -656,8 +656,9 @@ var _SiteManager = class _SiteManager {
|
|
|
656
656
|
const logs = this.debugLogs.slice(0, 50);
|
|
657
657
|
const errorsInLog = logs.filter((l) => l.level === "error").length;
|
|
658
658
|
const clearBtn = `<button data-action="clear-logs" style="background:rgba(255,255,255,0.08);border:none;color:${MUTED};cursor:pointer;font-size:9px;font-family:inherit;padding:2px 7px;border-radius:3px">Clear</button>`;
|
|
659
|
+
const copyBtn = `<button data-action="copy-logs" style="background:rgba(255,255,255,0.08);border:none;color:${MUTED};cursor:pointer;font-size:9px;font-family:inherit;padding:2px 7px;border-radius:3px">Copy</button>`;
|
|
659
660
|
const errBadge = errorsInLog > 0 ? `<span style="font-size:9px;color:${RED}">${errorsInLog} error${errorsInLog > 1 ? "s" : ""}</span>` : "";
|
|
660
|
-
const logHeader = `<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px">${errBadge || `<span></span>`}${clearBtn}</div>`;
|
|
661
|
+
const logHeader = `<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px">${errBadge || `<span></span>`}<div style="display:flex;gap:4px">${copyBtn}${clearBtn}</div></div>`;
|
|
661
662
|
if (logs.length === 0) {
|
|
662
663
|
content = logHeader + `<div style="color:${MUTED};padding:12px;text-align:center">No logs yet</div>`;
|
|
663
664
|
} else {
|
|
@@ -817,6 +818,15 @@ var _SiteManager = class _SiteManager {
|
|
|
817
818
|
await this.fetchConfig();
|
|
818
819
|
feedback("Config refreshed", true);
|
|
819
820
|
break;
|
|
821
|
+
case "copy-logs": {
|
|
822
|
+
const text = this.debugLogs.slice().reverse().map((l) => `[${l.ts}] [${l.level.toUpperCase()}] ${l.msg}`).join("\n");
|
|
823
|
+
void navigator.clipboard.writeText(text).then(() => {
|
|
824
|
+
feedback(`Copied ${this.debugLogs.length} log line${this.debugLogs.length !== 1 ? "s" : ""}`, true);
|
|
825
|
+
}).catch(() => {
|
|
826
|
+
feedback("Copy failed \u2014 clipboard not available", false);
|
|
827
|
+
});
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
820
830
|
case "clear-logs":
|
|
821
831
|
this.debugLogs = [];
|
|
822
832
|
this.testFeedback = [];
|
package/dist/index.mjs
CHANGED
|
@@ -63,8 +63,7 @@ var _SiteManager = class _SiteManager {
|
|
|
63
63
|
// 1 hour
|
|
64
64
|
onUpdateAvailable: config.onUpdateAvailable,
|
|
65
65
|
onUpdateRequired: config.onUpdateRequired,
|
|
66
|
-
debugMode: (_f = config.debugMode) != null ? _f : false
|
|
67
|
-
environment: config.environment
|
|
66
|
+
debugMode: (_f = config.debugMode) != null ? _f : false
|
|
68
67
|
};
|
|
69
68
|
this.loadDismissedMessages();
|
|
70
69
|
}
|
|
@@ -72,7 +71,6 @@ var _SiteManager = class _SiteManager {
|
|
|
72
71
|
* Initialize and start the site manager
|
|
73
72
|
*/
|
|
74
73
|
async init() {
|
|
75
|
-
var _a;
|
|
76
74
|
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
77
75
|
console.warn(
|
|
78
76
|
"Featurely Site Manager: Can only be initialized in a browser environment"
|
|
@@ -82,7 +80,7 @@ var _SiteManager = class _SiteManager {
|
|
|
82
80
|
if (this.config.debugMode) {
|
|
83
81
|
this.setupDebugOverlay();
|
|
84
82
|
}
|
|
85
|
-
this.debugLog("info", `[init] v1.1.
|
|
83
|
+
this.debugLog("info", `[init] v1.1.16 | project: ${this.config.projectId} | hostname: ${typeof window !== "undefined" ? window.location.hostname : "\u2014"}`);
|
|
86
84
|
this.debugLog("info", `[init] analytics: ${this.config.enableAnalytics ? "on" : "off"} | poll: ${this.config.pollInterval}ms | debug: ${this.config.debugMode ? "on" : "off"}`);
|
|
87
85
|
if (this.config.enableAnalytics) {
|
|
88
86
|
this.debugLog("info", "[init] starting analytics + page tracking");
|
|
@@ -331,10 +329,12 @@ var _SiteManager = class _SiteManager {
|
|
|
331
329
|
if (newConfig.debugMode === true && !this.debugOverlayEl) {
|
|
332
330
|
this.setupDebugOverlay();
|
|
333
331
|
}
|
|
334
|
-
if (!this.debugOverlayEl
|
|
332
|
+
if (!this.debugOverlayEl) {
|
|
333
|
+
const hostname = typeof window !== "undefined" ? window.location.hostname : "";
|
|
335
334
|
const envs = newConfig.environments;
|
|
336
|
-
const
|
|
337
|
-
if ((
|
|
335
|
+
const matchedEnv = hostname ? envs == null ? void 0 : envs.find((e) => typeof e.url === "string" && e.url !== "" && e.url === hostname) : void 0;
|
|
336
|
+
if ((matchedEnv == null ? void 0 : matchedEnv.debugEnabled) === true) {
|
|
337
|
+
this.debugLog("info", `[env] matched environment "${matchedEnv.name}" (${hostname})`);
|
|
338
338
|
this.setupDebugOverlay();
|
|
339
339
|
}
|
|
340
340
|
}
|
|
@@ -594,9 +594,9 @@ var _SiteManager = class _SiteManager {
|
|
|
594
594
|
const flagCount = (_c = (_b = sc == null ? void 0 : sc.featureFlags) == null ? void 0 : _b.length) != null ? _c : 0;
|
|
595
595
|
const msgCount = (_e = (_d = sc == null ? void 0 : sc.messages) == null ? void 0 : _d.length) != null ? _e : 0;
|
|
596
596
|
content = `
|
|
597
|
-
${row("SDK Version", "1.1.
|
|
597
|
+
${row("SDK Version", "1.1.16")}
|
|
598
598
|
${row("Project", cfg.projectId)}
|
|
599
|
-
${row("
|
|
599
|
+
${row("Hostname", typeof window !== "undefined" ? window.location.hostname : "\u2014")}
|
|
600
600
|
${row("API URL", cfg.apiUrl)}
|
|
601
601
|
${row("Maintenance", maintenance)}
|
|
602
602
|
${row("Feature Flags", `${flagCount} active`)}
|
|
@@ -621,8 +621,9 @@ var _SiteManager = class _SiteManager {
|
|
|
621
621
|
const logs = this.debugLogs.slice(0, 50);
|
|
622
622
|
const errorsInLog = logs.filter((l) => l.level === "error").length;
|
|
623
623
|
const clearBtn = `<button data-action="clear-logs" style="background:rgba(255,255,255,0.08);border:none;color:${MUTED};cursor:pointer;font-size:9px;font-family:inherit;padding:2px 7px;border-radius:3px">Clear</button>`;
|
|
624
|
+
const copyBtn = `<button data-action="copy-logs" style="background:rgba(255,255,255,0.08);border:none;color:${MUTED};cursor:pointer;font-size:9px;font-family:inherit;padding:2px 7px;border-radius:3px">Copy</button>`;
|
|
624
625
|
const errBadge = errorsInLog > 0 ? `<span style="font-size:9px;color:${RED}">${errorsInLog} error${errorsInLog > 1 ? "s" : ""}</span>` : "";
|
|
625
|
-
const logHeader = `<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px">${errBadge || `<span></span>`}${clearBtn}</div>`;
|
|
626
|
+
const logHeader = `<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:4px">${errBadge || `<span></span>`}<div style="display:flex;gap:4px">${copyBtn}${clearBtn}</div></div>`;
|
|
626
627
|
if (logs.length === 0) {
|
|
627
628
|
content = logHeader + `<div style="color:${MUTED};padding:12px;text-align:center">No logs yet</div>`;
|
|
628
629
|
} else {
|
|
@@ -782,6 +783,15 @@ var _SiteManager = class _SiteManager {
|
|
|
782
783
|
await this.fetchConfig();
|
|
783
784
|
feedback("Config refreshed", true);
|
|
784
785
|
break;
|
|
786
|
+
case "copy-logs": {
|
|
787
|
+
const text = this.debugLogs.slice().reverse().map((l) => `[${l.ts}] [${l.level.toUpperCase()}] ${l.msg}`).join("\n");
|
|
788
|
+
void navigator.clipboard.writeText(text).then(() => {
|
|
789
|
+
feedback(`Copied ${this.debugLogs.length} log line${this.debugLogs.length !== 1 ? "s" : ""}`, true);
|
|
790
|
+
}).catch(() => {
|
|
791
|
+
feedback("Copy failed \u2014 clipboard not available", false);
|
|
792
|
+
});
|
|
793
|
+
break;
|
|
794
|
+
}
|
|
785
795
|
case "clear-logs":
|
|
786
796
|
this.debugLogs = [];
|
|
787
797
|
this.testFeedback = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "featurely-site-manager",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
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",
|