featurely-site-manager 1.1.26 → 1.1.29

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # featurely-site-manager
2
2
 
3
- Powerful site management SDK for controlling maintenance mode, displaying status messages, and managing site-wide features from your Featurely dashboard.
3
+ Powerful site management SDK for controlling maintenance mode, displaying status messages, managing site-wide features, and scanning your project's dependencies for vulnerabilities — all from your Featurely dashboard.
4
4
 
5
5
  ## 📦 Installation
6
6
 
@@ -8,7 +8,63 @@ Powerful site management SDK for controlling maintenance mode, displaying status
8
8
  npm install featurely-site-manager
9
9
  ```
10
10
 
11
- ## 🚀 Quick Start
11
+ ## 🔍 Package Security Scanning (CLI)
12
+
13
+ Scan your project's dependencies for outdated versions, known CVEs, and breaking changes. Results appear instantly in your Featurely dashboard under **Package security**.
14
+
15
+ ### Run a scan
16
+
17
+ ```bash
18
+ npx featurely-site-manager scan packages \
19
+ --key YOUR_API_KEY \
20
+ --project YOUR_PROJECT_ID
21
+ ```
22
+
23
+ Run this from the directory that contains your `package.json`. After the first scan your package list is stored — use the **Re-scan** button in the dashboard to re-check without the CLI.
24
+
25
+ ### What gets reported
26
+
27
+ | Check | Source |
28
+ | --------------------------------------------- | -------------------------------------------- |
29
+ | Installed vs latest version | npm registry |
30
+ | Breaking change detection (major bump) | semver comparison |
31
+ | Known CVEs — critical / high / moderate / low | [OSV database](https://osv.dev) (GHSA + NVD) |
32
+ | Deprecated packages | npm registry |
33
+ | License (SPDX) | npm registry |
34
+
35
+ ### GitHub Actions — automatic scanning
36
+
37
+ Add to `.github/workflows/featurely-scan.yml` and set `FEATURELY_API_KEY` + `FEATURELY_PROJECT_ID` in your repository secrets.
38
+
39
+ ```yaml
40
+ name: Featurely package scan
41
+
42
+ on:
43
+ push:
44
+ branches: [main]
45
+ paths:
46
+ - "package.json"
47
+ - "package-lock.json"
48
+ - "yarn.lock"
49
+ - "pnpm-lock.yaml"
50
+ workflow_dispatch:
51
+
52
+ jobs:
53
+ scan:
54
+ runs-on: ubuntu-latest
55
+ steps:
56
+ - uses: actions/checkout@v4
57
+ - uses: actions/setup-node@v4
58
+ with:
59
+ node-version: "20"
60
+ - name: Run Featurely package scan
61
+ run: |
62
+ npx featurely-site-manager scan packages \
63
+ --key ${{ secrets.FEATURELY_API_KEY }} \
64
+ --project ${{ secrets.FEATURELY_PROJECT_ID }}
65
+ ```
66
+
67
+ ## 🚀 Quick Start (SDK)
12
68
 
13
69
  ```typescript
14
70
  import { SiteManager } from "featurely-site-manager";
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.mjs ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import { readFileSync } from "fs";
5
+ import { resolve } from "path";
6
+ function parseArgs(argv) {
7
+ const args = {};
8
+ for (let i = 0; i < argv.length; i++) {
9
+ if (argv[i].startsWith("--") && i + 1 < argv.length && !argv[i + 1].startsWith("--")) {
10
+ args[argv[i].slice(2)] = argv[i + 1];
11
+ i++;
12
+ }
13
+ }
14
+ return args;
15
+ }
16
+ async function main() {
17
+ var _a, _b, _c;
18
+ const rawArgs = process.argv.slice(2);
19
+ const isScanPackages = rawArgs[0] === "scan" && rawArgs[1] === "packages";
20
+ if (!isScanPackages) {
21
+ console.error(
22
+ "Usage: featurely-site-manager scan packages --key <api-key> --project <project-id>"
23
+ );
24
+ process.exit(1);
25
+ }
26
+ const args = parseArgs(rawArgs.slice(2));
27
+ const apiKey = args["key"];
28
+ const projectId = args["project"];
29
+ const baseUrl = (_a = args["url"]) != null ? _a : "https://featurely.no";
30
+ if (!apiKey) {
31
+ console.error("Error: --key is required");
32
+ process.exit(1);
33
+ }
34
+ if (!projectId) {
35
+ console.error("Error: --project is required");
36
+ process.exit(1);
37
+ }
38
+ const pkgPath = resolve(process.cwd(), "package.json");
39
+ let pkgJson;
40
+ try {
41
+ pkgJson = JSON.parse(readFileSync(pkgPath, "utf8"));
42
+ } catch {
43
+ console.error(`Error: Could not read package.json at ${pkgPath}`);
44
+ process.exit(1);
45
+ }
46
+ const deps = (_b = pkgJson.dependencies) != null ? _b : {};
47
+ const devDeps = (_c = pkgJson.devDependencies) != null ? _c : {};
48
+ const packages = [
49
+ ...Object.entries(deps).map(([name, version]) => ({
50
+ name,
51
+ version: version.replace(/^[\^~>=<]/, "")
52
+ })),
53
+ ...Object.entries(devDeps).map(([name, version]) => ({
54
+ name,
55
+ version: version.replace(/^[\^~>=<]/, "")
56
+ }))
57
+ ];
58
+ if (packages.length === 0) {
59
+ console.log("No dependencies found in package.json \u2014 nothing to scan.");
60
+ process.exit(0);
61
+ }
62
+ console.log(`Scanning ${packages.length} packages for project ${projectId}\u2026`);
63
+ const url = `${baseUrl}/api/projects/${projectId}/packages`;
64
+ let res;
65
+ try {
66
+ res = await fetch(url, {
67
+ method: "POST",
68
+ headers: {
69
+ "Content-Type": "application/json",
70
+ "x-api-key": apiKey
71
+ },
72
+ body: JSON.stringify({ packages })
73
+ });
74
+ } catch (err) {
75
+ console.error("Error: Network request failed.", err);
76
+ process.exit(1);
77
+ }
78
+ if (!res.ok) {
79
+ const body = await res.text();
80
+ console.error(`Error: API returned ${res.status}. ${body}`);
81
+ process.exit(1);
82
+ }
83
+ const data = await res.json();
84
+ const count = Array.isArray(data.packages) ? data.packages.length : packages.length;
85
+ console.log(
86
+ `\u2713 Scan complete. ${count} packages analysed. View results in your Featurely dashboard.`
87
+ );
88
+ }
89
+ main();
@@ -0,0 +1,255 @@
1
+ declare const SDK_VERSION = "1.1.28";
2
+ type MessageType = "info" | "warning" | "error" | "success";
3
+ type MessagePosition = "top" | "bottom";
4
+ type MessageStyle = "banner" | "toast";
5
+ interface StatusMessage {
6
+ id: string;
7
+ type: MessageType;
8
+ title: string;
9
+ message: string;
10
+ icon?: string;
11
+ dismissible: boolean;
12
+ position: MessagePosition;
13
+ style: MessageStyle;
14
+ expiresAt?: string;
15
+ startsAt?: string;
16
+ targetPages?: string[];
17
+ cta?: {
18
+ text: string;
19
+ url: string;
20
+ action?: string;
21
+ };
22
+ priority?: number;
23
+ }
24
+ interface FeatureFlag {
25
+ id: string;
26
+ key: string;
27
+ name: string;
28
+ description?: string;
29
+ enabled: boolean;
30
+ rolloutPercentage?: number;
31
+ targetEmails?: string[];
32
+ excludeEmails?: string[];
33
+ variants?: {
34
+ key: string;
35
+ name: string;
36
+ weight: number;
37
+ }[];
38
+ defaultVariant?: string;
39
+ targetAttributes?: Array<{
40
+ attribute: string;
41
+ operator: "equals" | "not_equals" | "contains" | "greater_than" | "less_than";
42
+ value: string | number | boolean;
43
+ }>;
44
+ }
45
+ interface MaintenanceConfig {
46
+ enabled: boolean;
47
+ type: "default" | "custom";
48
+ customHtml?: string;
49
+ expectedRestoration?: string;
50
+ showStatusLink: boolean;
51
+ statusPageUrl?: string;
52
+ whitelist: {
53
+ localStorageKeys?: string[];
54
+ emails?: string[];
55
+ ips?: string[];
56
+ };
57
+ }
58
+ interface AppVersion {
59
+ version: string;
60
+ title: string;
61
+ releaseNotes?: string;
62
+ downloadUrl?: string;
63
+ platformUrls?: Record<string, string>;
64
+ releaseDate: string;
65
+ isBeta?: boolean;
66
+ rolloutPercentage?: number;
67
+ }
68
+ interface VersionCheckResponse {
69
+ updateAvailable: boolean;
70
+ updateRequired: boolean;
71
+ updateRecommended: boolean;
72
+ updateType?: "major" | "minor" | "patch" | "hash" | "unknown";
73
+ latestVersion?: AppVersion;
74
+ }
75
+ interface VersionUpdateRules {
76
+ major?: "required" | "available";
77
+ minor?: "required" | "available";
78
+ patch?: "required" | "recommended" | "available";
79
+ }
80
+ interface AnalyticsConfig {
81
+ urlWhitelist?: string[];
82
+ urlBlacklist?: string[];
83
+ userWhitelist?: string[];
84
+ userBlacklist?: string[];
85
+ sampleRate?: number;
86
+ trackPageViews?: boolean;
87
+ trackWebVitals?: boolean;
88
+ trackOutboundLinks?: boolean;
89
+ trackSessionStart?: boolean;
90
+ flushInterval?: number;
91
+ }
92
+ interface SdkVersionRequirement {
93
+ packageName: string;
94
+ displayName: string;
95
+ currentVersion: string;
96
+ minimumVersion: string;
97
+ updateCommand: string;
98
+ changelog?: string;
99
+ }
100
+ interface SiteConfig {
101
+ maintenance: MaintenanceConfig;
102
+ messages: StatusMessage[];
103
+ featureFlags: FeatureFlag[];
104
+ lastUpdated: string;
105
+ analyticsConfig?: AnalyticsConfig | null;
106
+ sdkVersions?: SdkVersionRequirement[];
107
+ }
108
+ interface SiteManagerConfig {
109
+ apiKey: string;
110
+ projectId: string;
111
+ apiUrl?: string;
112
+ environment?: string;
113
+ pollInterval?: number;
114
+ userEmail?: string;
115
+ bypassCheck?: () => boolean;
116
+ onMaintenanceEnabled?: (config: MaintenanceConfig) => void;
117
+ onMaintenanceDisabled?: () => void;
118
+ onMessageReceived?: (message: StatusMessage) => void;
119
+ onMessageDismissed?: (messageId: string) => void;
120
+ onFeatureFlagsUpdated?: (flags: FeatureFlag[]) => void;
121
+ userId?: string;
122
+ customAttributes?: Record<string, string | number | boolean>;
123
+ bootstrapFlags?: Record<string, boolean>;
124
+ enableAnalytics?: boolean;
125
+ analyticsFlushInterval?: number;
126
+ appVersion?: string;
127
+ enableVersionCheck?: boolean;
128
+ versionCheckInterval?: number;
129
+ onUpdateAvailable?: (versionInfo: VersionCheckResponse) => void;
130
+ onUpdateRequired?: (versionInfo: VersionCheckResponse) => void;
131
+ platform?: string;
132
+ updateRules?: VersionUpdateRules;
133
+ onError?: (error: Error) => void;
134
+ debugMode?: boolean;
135
+ debugSecret?: string;
136
+ autoInjectBanners?: boolean;
137
+ autoCaptureClicks?: boolean;
138
+ }
139
+ declare class SiteManager {
140
+ private config;
141
+ private siteConfig;
142
+ private configETag;
143
+ private analyticsConfig;
144
+ private _sessionSampled;
145
+ private _sdkUpdateToastShown;
146
+ private pollIntervalId;
147
+ private versionCheckIntervalId;
148
+ private messageContainers;
149
+ private dismissedMessages;
150
+ private featureFlagBuckets;
151
+ private analyticsQueue;
152
+ private analyticsFlushIntervalId;
153
+ private sessionId;
154
+ private consecutiveFetchFailures;
155
+ private pageTrackingSetup;
156
+ private currentPagePath;
157
+ private currentPageSearch;
158
+ private pageEntryTime;
159
+ private static readonly MAX_CONSECUTIVE_FAILURES;
160
+ private lastVersionCheck;
161
+ private debugOverlayEl;
162
+ private debugRefreshId;
163
+ private debugLogs;
164
+ private networkLog;
165
+ private analyticsEventsSent;
166
+ private debugMinimized;
167
+ private debugTab;
168
+ private recentAnalyticsEvents;
169
+ private testFlagKey;
170
+ private testFeedback;
171
+ private errorCount;
172
+ private consoleIntercepted;
173
+ private visitorId;
174
+ private flagOverrides;
175
+ private originalConsoleError;
176
+ private originalConsoleWarn;
177
+ constructor(config: SiteManagerConfig);
178
+ init(): Promise<void>;
179
+ destroy(): void;
180
+ setUser(email: string, userId?: string, customAttributes?: Record<string, string | number | boolean>): void;
181
+ isFeatureEnabled(flagKey: string, defaultValue?: boolean): boolean;
182
+ getFeatureVariant(flagKey: string): string | null;
183
+ getAllFeatureFlags(): FeatureFlag[];
184
+ getEnabledFeatures(): string[];
185
+ getActiveEnvironment(): {
186
+ id: string;
187
+ name: string;
188
+ slug: string;
189
+ } | null;
190
+ isErrorLoggingEnabled(): boolean;
191
+ overrideFlag(flagKey: string, value: boolean | null): void;
192
+ isInMaintenanceMode(): boolean;
193
+ getActiveMessages(): StatusMessage[];
194
+ refresh(): Promise<void>;
195
+ private matchesPattern;
196
+ private matchesAnyPattern;
197
+ private isSessionSampled;
198
+ trackEvent(eventName: string, properties?: Record<string, string | number | boolean>): void;
199
+ track404(path?: string): void;
200
+ private fetchConfig;
201
+ private startPolling;
202
+ private stopPolling;
203
+ private startAnalyticsFlushing;
204
+ private stopAnalyticsFlushing;
205
+ private flushAnalytics;
206
+ private debugLog;
207
+ private debugNetwork;
208
+ private stopDebugOverlay;
209
+ private setupGlobalErrorCapture;
210
+ private setupDebugOverlay;
211
+ private renderDebugOverlay;
212
+ private handleTestAction;
213
+ private parseUtmParams;
214
+ private setupWebVitals;
215
+ private setupOutboundLinkTracking;
216
+ private setupAutoClickCapture;
217
+ private setupPageTracking;
218
+ private trackPageView;
219
+ private trackPageExit;
220
+ private onNavigate;
221
+ private generateSessionId;
222
+ private compareVersions;
223
+ private showSdkUpdateToast;
224
+ checkVersion(currentVersion?: string): Promise<VersionCheckResponse | null>;
225
+ forceUpdateWeb(): Promise<void>;
226
+ getLastVersionCheck(): VersionCheckResponse | null;
227
+ private startVersionChecking;
228
+ private stopVersionChecking;
229
+ private resolveEnvironment;
230
+ private hostnameMatchesEnv;
231
+ private matchHostnamePattern;
232
+ private evaluateFeatureFlag;
233
+ private getUserBucket;
234
+ private simpleHash;
235
+ private getAnonymousId;
236
+ private getOrCreateVisitorId;
237
+ private checkMaintenanceMode;
238
+ private enableMaintenanceMode;
239
+ private disableMaintenanceMode;
240
+ private shouldBypassMaintenance;
241
+ private showMaintenancePage;
242
+ private hideMaintenancePage;
243
+ private getDefaultMaintenanceHtml;
244
+ private updateMessages;
245
+ private showMessage;
246
+ private dismissMessage;
247
+ private clearMessages;
248
+ private handleMessageAction;
249
+ private getDefaultIcon;
250
+ private loadDismissedMessages;
251
+ private saveDismissedMessages;
252
+ private injectStyles;
253
+ }
254
+
255
+ export { type AnalyticsConfig, type AppVersion, type FeatureFlag, type MaintenanceConfig, type MessagePosition, type MessageStyle, type MessageType, SDK_VERSION, type SdkVersionRequirement, type SiteConfig, SiteManager, type SiteManagerConfig, type StatusMessage, type VersionCheckResponse, type VersionUpdateRules, SiteManager as default };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ declare const SDK_VERSION = "1.1.28";
1
2
  type MessageType = "info" | "warning" | "error" | "success";
2
3
  type MessagePosition = "top" | "bottom";
3
4
  type MessageStyle = "banner" | "toast";
@@ -76,11 +77,33 @@ interface VersionUpdateRules {
76
77
  minor?: "required" | "available";
77
78
  patch?: "required" | "recommended" | "available";
78
79
  }
80
+ interface AnalyticsConfig {
81
+ urlWhitelist?: string[];
82
+ urlBlacklist?: string[];
83
+ userWhitelist?: string[];
84
+ userBlacklist?: string[];
85
+ sampleRate?: number;
86
+ trackPageViews?: boolean;
87
+ trackWebVitals?: boolean;
88
+ trackOutboundLinks?: boolean;
89
+ trackSessionStart?: boolean;
90
+ flushInterval?: number;
91
+ }
92
+ interface SdkVersionRequirement {
93
+ packageName: string;
94
+ displayName: string;
95
+ currentVersion: string;
96
+ minimumVersion: string;
97
+ updateCommand: string;
98
+ changelog?: string;
99
+ }
79
100
  interface SiteConfig {
80
101
  maintenance: MaintenanceConfig;
81
102
  messages: StatusMessage[];
82
103
  featureFlags: FeatureFlag[];
83
104
  lastUpdated: string;
105
+ analyticsConfig?: AnalyticsConfig | null;
106
+ sdkVersions?: SdkVersionRequirement[];
84
107
  }
85
108
  interface SiteManagerConfig {
86
109
  apiKey: string;
@@ -117,6 +140,9 @@ declare class SiteManager {
117
140
  private config;
118
141
  private siteConfig;
119
142
  private configETag;
143
+ private analyticsConfig;
144
+ private _sessionSampled;
145
+ private _sdkUpdateToastShown;
120
146
  private pollIntervalId;
121
147
  private versionCheckIntervalId;
122
148
  private messageContainers;
@@ -166,6 +192,9 @@ declare class SiteManager {
166
192
  isInMaintenanceMode(): boolean;
167
193
  getActiveMessages(): StatusMessage[];
168
194
  refresh(): Promise<void>;
195
+ private matchesPattern;
196
+ private matchesAnyPattern;
197
+ private isSessionSampled;
169
198
  trackEvent(eventName: string, properties?: Record<string, string | number | boolean>): void;
170
199
  track404(path?: string): void;
171
200
  private fetchConfig;
@@ -190,6 +219,8 @@ declare class SiteManager {
190
219
  private trackPageExit;
191
220
  private onNavigate;
192
221
  private generateSessionId;
222
+ private compareVersions;
223
+ private showSdkUpdateToast;
193
224
  checkVersion(currentVersion?: string): Promise<VersionCheckResponse | null>;
194
225
  forceUpdateWeb(): Promise<void>;
195
226
  getLastVersionCheck(): VersionCheckResponse | null;
@@ -221,4 +252,4 @@ declare class SiteManager {
221
252
  private injectStyles;
222
253
  }
223
254
 
224
- export { type AppVersion, type FeatureFlag, type MaintenanceConfig, type MessagePosition, type MessageStyle, type MessageType, type SiteConfig, SiteManager, type SiteManagerConfig, type StatusMessage, type VersionCheckResponse, type VersionUpdateRules, SiteManager as default };
255
+ export { type AnalyticsConfig, type AppVersion, type FeatureFlag, type MaintenanceConfig, type MessagePosition, type MessageStyle, type MessageType, SDK_VERSION, type SdkVersionRequirement, type SiteConfig, SiteManager, type SiteManagerConfig, type StatusMessage, type VersionCheckResponse, type VersionUpdateRules, SiteManager as default };