@togglely/sdk 1.1.7 → 1.2.0
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 +210 -38
- package/dist/index.umd.js +125 -42
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +35 -35
package/README.md
CHANGED
|
@@ -1,65 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Togglely Vanilla JavaScript SDK
|
|
2
2
|
|
|
3
|
-
Vanilla JavaScript SDK for Togglely
|
|
3
|
+
Vanilla JavaScript SDK for [Togglely](https://togglely.io) feature flag management. Works in browsers and Node.js without any framework.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🌍 **Universal** - Works in browser and Node.js
|
|
8
|
+
- 📦 **Zero dependencies** - Lightweight and fast
|
|
9
|
+
- 💾 **Offline support** - JSON file, environment variables, or window object
|
|
10
|
+
- 🎯 **Simple API** - Easy to use with global instance
|
|
11
|
+
- 🔒 **TypeScript** - Full type support
|
|
6
12
|
|
|
7
13
|
## Installation
|
|
8
14
|
|
|
15
|
+
### NPM
|
|
16
|
+
|
|
9
17
|
```bash
|
|
10
18
|
npm install @togglely/sdk
|
|
11
19
|
```
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
### CDN
|
|
14
22
|
|
|
15
23
|
```html
|
|
16
24
|
<script src="https://unpkg.com/@togglely/sdk/dist/index.umd.min.js"></script>
|
|
17
25
|
```
|
|
18
26
|
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
### ES Modules
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
import { TogglelyClient } from '@togglely/sdk';
|
|
25
|
-
|
|
26
|
-
const client = new TogglelyClient({
|
|
27
|
-
apiKey: 'your-api-key',
|
|
28
|
-
environment: 'production',
|
|
29
|
-
baseUrl: 'https://your-togglely-instance.com'
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const isEnabled = await client.isEnabled('new-feature', false);
|
|
33
|
-
```
|
|
27
|
+
## Quick Start
|
|
34
28
|
|
|
35
|
-
###
|
|
29
|
+
### Browser (Module)
|
|
36
30
|
|
|
37
31
|
```javascript
|
|
38
32
|
import { initTogglely, isEnabled } from '@togglely/sdk';
|
|
39
33
|
|
|
40
|
-
// Initialize
|
|
34
|
+
// Initialize
|
|
41
35
|
initTogglely({
|
|
42
36
|
apiKey: 'your-api-key',
|
|
37
|
+
project: 'my-project',
|
|
43
38
|
environment: 'production',
|
|
44
|
-
baseUrl: 'https://
|
|
39
|
+
baseUrl: 'https://togglely.io',
|
|
45
40
|
});
|
|
46
41
|
|
|
47
42
|
// Use global helpers
|
|
48
|
-
const
|
|
43
|
+
const newFeature = await isEnabled('new-feature', false);
|
|
44
|
+
if (newFeature) {
|
|
45
|
+
document.getElementById('new-feature').style.display = 'block';
|
|
46
|
+
}
|
|
49
47
|
```
|
|
50
48
|
|
|
51
|
-
### CDN
|
|
49
|
+
### Browser (CDN)
|
|
52
50
|
|
|
53
51
|
```html
|
|
54
52
|
<script src="https://unpkg.com/@togglely/sdk/dist/index.umd.min.js"></script>
|
|
55
53
|
<script>
|
|
56
|
-
|
|
54
|
+
Togglely.initTogglely({
|
|
57
55
|
apiKey: 'your-api-key',
|
|
56
|
+
project: 'my-project',
|
|
58
57
|
environment: 'production',
|
|
59
|
-
baseUrl: 'https://
|
|
58
|
+
baseUrl: 'https://togglely.io',
|
|
60
59
|
});
|
|
61
60
|
|
|
62
|
-
|
|
61
|
+
Togglely.isEnabled('new-feature').then(function(enabled) {
|
|
63
62
|
if (enabled) {
|
|
64
63
|
document.getElementById('new-feature').style.display = 'block';
|
|
65
64
|
}
|
|
@@ -67,26 +66,199 @@ const enabled = await isEnabled('new-feature', false);
|
|
|
67
66
|
</script>
|
|
68
67
|
```
|
|
69
68
|
|
|
70
|
-
###
|
|
69
|
+
### Node.js
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const { TogglelyClient } = require('@togglely/sdk');
|
|
73
|
+
|
|
74
|
+
const client = new TogglelyClient({
|
|
75
|
+
apiKey: 'your-api-key',
|
|
76
|
+
project: 'my-project',
|
|
77
|
+
environment: 'production',
|
|
78
|
+
baseUrl: 'https://togglely.io',
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const isEnabled = await client.isEnabled('new-feature', false);
|
|
82
|
+
console.log('New feature:', isEnabled);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Configuration
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
initTogglely({
|
|
89
|
+
apiKey: 'your-api-key',
|
|
90
|
+
project: 'my-project',
|
|
91
|
+
environment: 'production',
|
|
92
|
+
baseUrl: 'https://togglely.io',
|
|
93
|
+
tenantId: 'brand-a', // For multi-brand projects
|
|
94
|
+
offlineJsonPath: '/toggles.json', // Offline fallback
|
|
95
|
+
timeout: 5000, // Request timeout
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Global Helpers
|
|
100
|
+
|
|
101
|
+
After calling `initTogglely()`, you can use these global helpers:
|
|
71
102
|
|
|
72
103
|
```javascript
|
|
73
|
-
import {
|
|
104
|
+
import { isEnabled, getString, getNumber, getJSON } from '@togglely/sdk';
|
|
105
|
+
|
|
106
|
+
// Boolean toggle
|
|
107
|
+
const enabled = await isEnabled('new-feature', false);
|
|
108
|
+
|
|
109
|
+
// String toggle
|
|
110
|
+
const message = await getString('welcome-message', 'Hello!');
|
|
111
|
+
|
|
112
|
+
// Number toggle
|
|
113
|
+
const limit = await getNumber('max-items', 10);
|
|
114
|
+
|
|
115
|
+
// JSON toggle
|
|
116
|
+
const config = await getJSON('app-config', { theme: 'dark' });
|
|
117
|
+
```
|
|
74
118
|
|
|
75
|
-
|
|
76
|
-
togglelyToggle('#new-feature', 'new-feature');
|
|
119
|
+
## DOM Helpers
|
|
77
120
|
|
|
78
|
-
|
|
79
|
-
|
|
121
|
+
### togglelyToggle
|
|
122
|
+
|
|
123
|
+
Show/hide elements based on a toggle:
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
import { togglelyToggle } from '@togglely/sdk';
|
|
127
|
+
|
|
128
|
+
// Show element when toggle is enabled
|
|
129
|
+
await togglelyToggle('#new-feature', 'new-feature');
|
|
130
|
+
|
|
131
|
+
// Hide element when toggle is disabled (invert)
|
|
132
|
+
await togglelyToggle('#old-feature', 'new-feature', { invert: true });
|
|
133
|
+
|
|
134
|
+
// With default value
|
|
135
|
+
await togglelyToggle('#beta', 'beta-feature', { defaultValue: true });
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### togglelyInit
|
|
139
|
+
|
|
140
|
+
Initialize multiple elements:
|
|
141
|
+
|
|
142
|
+
```javascript
|
|
143
|
+
import { togglelyInit } from '@togglely/sdk';
|
|
144
|
+
|
|
145
|
+
const unsubscribe = togglelyInit({
|
|
146
|
+
// Simple selectors
|
|
80
147
|
'new-feature': ['.new-feature', '.new-banner'],
|
|
81
|
-
|
|
148
|
+
|
|
149
|
+
// With options
|
|
82
150
|
'premium': {
|
|
83
151
|
selector: '.premium-content',
|
|
84
|
-
defaultValue: false
|
|
85
|
-
|
|
152
|
+
defaultValue: false
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
// Invert (hide when enabled)
|
|
156
|
+
'new-ui': {
|
|
157
|
+
selector: '.old-ui',
|
|
158
|
+
invert: true
|
|
86
159
|
}
|
|
87
160
|
});
|
|
161
|
+
|
|
162
|
+
// Cleanup
|
|
163
|
+
unsubscribe();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Offline Fallback
|
|
167
|
+
|
|
168
|
+
### Environment Variables (Node.js)
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
TOGGLELY_NEW_FEATURE=true
|
|
172
|
+
TOGGLELY_MAX_ITEMS=100
|
|
173
|
+
TOGGLELY_WELCOME_MESSAGE="Hello World"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
const client = new TogglelyClient({
|
|
178
|
+
apiKey: 'your-api-key',
|
|
179
|
+
project: 'my-project',
|
|
180
|
+
environment: 'production',
|
|
181
|
+
baseUrl: 'https://togglely.io',
|
|
182
|
+
envPrefix: 'TOGGLELY_', // Default
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Window Object (Browser)
|
|
187
|
+
|
|
188
|
+
```html
|
|
189
|
+
<script>
|
|
190
|
+
window.__TOGGLELY_TOGGLES = {
|
|
191
|
+
'new-feature': { value: true, enabled: true },
|
|
192
|
+
'max-items': { value: 100, enabled: true },
|
|
193
|
+
'welcome-message': { value: 'Hello World', enabled: true }
|
|
194
|
+
};
|
|
195
|
+
</script>
|
|
196
|
+
<script src="https://unpkg.com/@togglely/sdk/dist/index.umd.min.js"></script>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### JSON File
|
|
200
|
+
|
|
201
|
+
Generate offline JSON:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
togglely-pull --apiKey=xxx --project=my-project --environment=production --output=./toggles.json
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Use in your app:
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
initTogglely({
|
|
211
|
+
apiKey: 'your-api-key',
|
|
212
|
+
project: 'my-project',
|
|
213
|
+
environment: 'production',
|
|
214
|
+
baseUrl: 'https://togglely.io',
|
|
215
|
+
offlineJsonPath: '/toggles.json',
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Direct Client Usage
|
|
220
|
+
|
|
221
|
+
For more control, use the client directly:
|
|
222
|
+
|
|
223
|
+
```javascript
|
|
224
|
+
import { TogglelyClient } from '@togglely/sdk';
|
|
225
|
+
|
|
226
|
+
const client = new TogglelyClient({
|
|
227
|
+
apiKey: 'your-api-key',
|
|
228
|
+
project: 'my-project',
|
|
229
|
+
environment: 'production',
|
|
230
|
+
baseUrl: 'https://togglely.io',
|
|
231
|
+
tenantId: 'brand-a',
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// Set targeting context
|
|
235
|
+
client.setContext({ userId: '123', country: 'DE' });
|
|
236
|
+
|
|
237
|
+
// Check toggle
|
|
238
|
+
const enabled = await client.isEnabled('new-feature', false);
|
|
239
|
+
|
|
240
|
+
// Listen to events
|
|
241
|
+
client.on('ready', () => console.log('Ready!'));
|
|
242
|
+
client.on('offline', () => console.log('Offline mode'));
|
|
243
|
+
client.on('update', () => console.log('Toggles updated'));
|
|
244
|
+
|
|
245
|
+
// Get all toggles
|
|
246
|
+
const all = client.getAllToggles();
|
|
247
|
+
|
|
248
|
+
// Cleanup
|
|
249
|
+
client.destroy();
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Build-Time JSON Generation
|
|
253
|
+
|
|
254
|
+
```json
|
|
255
|
+
{
|
|
256
|
+
"scripts": {
|
|
257
|
+
"build": "togglely-pull --apiKey=$TOGGLELY_APIKEY --project=my-project --environment=production --output=./toggles.json"
|
|
258
|
+
}
|
|
259
|
+
}
|
|
88
260
|
```
|
|
89
261
|
|
|
90
|
-
##
|
|
262
|
+
## License
|
|
91
263
|
|
|
92
|
-
|
|
264
|
+
MIT
|
package/dist/index.umd.js
CHANGED
|
@@ -5,13 +5,16 @@
|
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Togglely Core SDK - Framework agnostic
|
|
8
|
+
* Togglely Core SDK - Framework agnostic feature flag management
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Real-time feature flag evaluation
|
|
12
|
+
* - Offline fallback via JSON file, environment variables, or window object
|
|
13
|
+
* - Multi-brand/tenant support
|
|
14
|
+
* - Type-safe flag access
|
|
15
|
+
* - Build-time JSON generation for offline-first deployment
|
|
14
16
|
*/
|
|
17
|
+
// ==================== Togglely Client ====================
|
|
15
18
|
class TogglelyClient {
|
|
16
19
|
constructor(config) {
|
|
17
20
|
this.toggles = new Map();
|
|
@@ -29,6 +32,7 @@
|
|
|
29
32
|
offlineFallback: true,
|
|
30
33
|
envPrefix: 'TOGGLELY_',
|
|
31
34
|
autoFetch: true,
|
|
35
|
+
offlineJsonPath: undefined,
|
|
32
36
|
...config
|
|
33
37
|
};
|
|
34
38
|
// Initialize event handlers
|
|
@@ -37,6 +41,13 @@
|
|
|
37
41
|
this.eventHandlers.set('error', new Set());
|
|
38
42
|
this.eventHandlers.set('offline', new Set());
|
|
39
43
|
this.eventHandlers.set('online', new Set());
|
|
44
|
+
// Set initial context if provided (including brandKey/tenantId)
|
|
45
|
+
const initialContext = { ...config.context };
|
|
46
|
+
if (config.brandKey)
|
|
47
|
+
initialContext.brandKey = config.brandKey;
|
|
48
|
+
if (config.tenantId)
|
|
49
|
+
initialContext.tenantId = config.tenantId;
|
|
50
|
+
this.context = initialContext;
|
|
40
51
|
// Load offline toggles first (if enabled)
|
|
41
52
|
if (this.config.offlineFallback) {
|
|
42
53
|
this.loadOfflineToggles();
|
|
@@ -87,24 +98,49 @@
|
|
|
87
98
|
return this.state.isOffline;
|
|
88
99
|
}
|
|
89
100
|
// ==================== Toggle Accessors ====================
|
|
101
|
+
/**
|
|
102
|
+
* Check if a boolean feature flag is enabled
|
|
103
|
+
* @param key - The flag key
|
|
104
|
+
* @param defaultValue - Default value if flag not found
|
|
105
|
+
* @returns Promise<boolean>
|
|
106
|
+
*/
|
|
90
107
|
async isEnabled(key, defaultValue = false) {
|
|
91
108
|
const value = await this.getValue(key);
|
|
92
|
-
if (value === null)
|
|
109
|
+
if (value === null) {
|
|
93
110
|
return defaultValue;
|
|
111
|
+
}
|
|
94
112
|
return value.enabled && value.value === true;
|
|
95
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Get a string feature flag value
|
|
116
|
+
* @param key - The flag key
|
|
117
|
+
* @param defaultValue - Default value if flag not found or disabled
|
|
118
|
+
* @returns Promise<string>
|
|
119
|
+
*/
|
|
96
120
|
async getString(key, defaultValue = '') {
|
|
97
121
|
const value = await this.getValue(key);
|
|
98
122
|
if (value === null || !value.enabled)
|
|
99
123
|
return defaultValue;
|
|
100
124
|
return String(value.value);
|
|
101
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Get a number feature flag value
|
|
128
|
+
* @param key - The flag key
|
|
129
|
+
* @param defaultValue - Default value if flag not found or disabled
|
|
130
|
+
* @returns Promise<number>
|
|
131
|
+
*/
|
|
102
132
|
async getNumber(key, defaultValue = 0) {
|
|
103
133
|
const value = await this.getValue(key);
|
|
104
134
|
if (value === null || !value.enabled)
|
|
105
135
|
return defaultValue;
|
|
106
136
|
return Number(value.value);
|
|
107
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Get a JSON feature flag value
|
|
140
|
+
* @param key - The flag key
|
|
141
|
+
* @param defaultValue - Default value if flag not found or disabled
|
|
142
|
+
* @returns Promise<T>
|
|
143
|
+
*/
|
|
108
144
|
async getJSON(key, defaultValue = {}) {
|
|
109
145
|
const value = await this.getValue(key);
|
|
110
146
|
if (value === null || !value.enabled)
|
|
@@ -119,6 +155,11 @@
|
|
|
119
155
|
}
|
|
120
156
|
return value.value;
|
|
121
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Get raw toggle value
|
|
160
|
+
* @param key - The flag key
|
|
161
|
+
* @returns Promise<ToggleValue | null>
|
|
162
|
+
*/
|
|
122
163
|
async getValue(key) {
|
|
123
164
|
// Try cache first - but only if no context is set
|
|
124
165
|
if (Object.keys(this.context).length === 0) {
|
|
@@ -130,29 +171,25 @@
|
|
|
130
171
|
// Fetch from server
|
|
131
172
|
try {
|
|
132
173
|
const params = new URLSearchParams();
|
|
174
|
+
if (this.config.apiKey)
|
|
175
|
+
params.set('apiKey', this.config.apiKey);
|
|
133
176
|
const brandKey = this.context.tenantId || this.context.brandKey;
|
|
134
177
|
if (brandKey)
|
|
135
|
-
params.set('
|
|
136
|
-
// Always send context if available (needed for targeting rules)
|
|
178
|
+
params.set('tenantId', String(brandKey));
|
|
137
179
|
if (Object.keys(this.context).length > 0) {
|
|
138
180
|
params.set('context', JSON.stringify(this.context));
|
|
139
181
|
}
|
|
140
182
|
const query = params.toString() ? `?${params.toString()}` : '';
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
'Authorization': `Bearer ${this.config.apiKey}`,
|
|
144
|
-
'Content-Type': 'application/json'
|
|
145
|
-
}
|
|
146
|
-
});
|
|
183
|
+
const url = `${this.config.baseUrl}/sdk/flags/${encodeURIComponent(this.config.project)}/${encodeURIComponent(this.config.environment)}/${encodeURIComponent(key)}${query}`;
|
|
184
|
+
const response = await this.fetchWithTimeout(url, { headers: { 'Content-Type': 'application/json' } });
|
|
147
185
|
if (!response.ok) {
|
|
148
186
|
if (response.status === 404) {
|
|
149
187
|
return null;
|
|
150
188
|
}
|
|
151
|
-
throw new Error(`HTTP ${response.status}`);
|
|
189
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
152
190
|
}
|
|
153
191
|
const data = await response.json();
|
|
154
192
|
this.toggles.set(key, data);
|
|
155
|
-
// Update state if we were offline
|
|
156
193
|
if (this.state.isOffline) {
|
|
157
194
|
this.state.isOffline = false;
|
|
158
195
|
this.emit('online');
|
|
@@ -161,14 +198,20 @@
|
|
|
161
198
|
}
|
|
162
199
|
catch (error) {
|
|
163
200
|
// Try offline fallback
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
201
|
+
if (this.config.offlineFallback) {
|
|
202
|
+
const offlineValue = this.getOfflineToggle(key);
|
|
203
|
+
if (offlineValue !== null) {
|
|
204
|
+
return offlineValue;
|
|
205
|
+
}
|
|
167
206
|
}
|
|
168
|
-
|
|
169
|
-
return
|
|
207
|
+
// Return safe default
|
|
208
|
+
return { value: false, enabled: false };
|
|
170
209
|
}
|
|
171
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Get all toggles
|
|
213
|
+
* @returns Record<string, ToggleValue>
|
|
214
|
+
*/
|
|
172
215
|
getAllToggles() {
|
|
173
216
|
const result = {};
|
|
174
217
|
this.toggles.forEach((value, key) => {
|
|
@@ -178,12 +221,28 @@
|
|
|
178
221
|
}
|
|
179
222
|
// ==================== Offline Fallback ====================
|
|
180
223
|
/**
|
|
181
|
-
* Load toggles from
|
|
182
|
-
*
|
|
224
|
+
* Load offline toggles from multiple sources (in priority order):
|
|
225
|
+
* 1. Inline offlineToggles from config
|
|
226
|
+
* 2. JSON file (if offlineJsonPath is set)
|
|
227
|
+
* 3. window.__TOGGLELY_TOGGLES (browser)
|
|
228
|
+
* 4. Environment variables (Node.js)
|
|
183
229
|
*/
|
|
184
230
|
loadOfflineToggles() {
|
|
185
231
|
try {
|
|
186
|
-
//
|
|
232
|
+
// Priority 1: Inline offline toggles from config
|
|
233
|
+
if (this.config.offlineToggles && Object.keys(this.config.offlineToggles).length > 0) {
|
|
234
|
+
for (const [key, value] of Object.entries(this.config.offlineToggles)) {
|
|
235
|
+
this.toggles.set(key, value);
|
|
236
|
+
}
|
|
237
|
+
this.offlineTogglesLoaded = true;
|
|
238
|
+
console.log('[Togglely] Loaded offline toggles from config');
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
// Priority 2: JSON file (browser only - fetch synchronously not possible, will try async)
|
|
242
|
+
if (this.config.offlineJsonPath && typeof window !== 'undefined') {
|
|
243
|
+
this.loadOfflineJsonFile(this.config.offlineJsonPath);
|
|
244
|
+
}
|
|
245
|
+
// Priority 3: Browser environment - check window.__TOGGLELY_TOGGLES
|
|
187
246
|
if (typeof window !== 'undefined' && window.__TOGGLELY_TOGGLES) {
|
|
188
247
|
const offlineToggles = window.__TOGGLELY_TOGGLES;
|
|
189
248
|
for (const [key, value] of Object.entries(offlineToggles)) {
|
|
@@ -193,12 +252,11 @@
|
|
|
193
252
|
console.log('[Togglely] Loaded offline toggles from window.__TOGGLELY_TOGGLES');
|
|
194
253
|
return;
|
|
195
254
|
}
|
|
196
|
-
// Node.js / Bun / Deno environment - check process.env
|
|
255
|
+
// Priority 4: Node.js / Bun / Deno environment - check process.env
|
|
197
256
|
if (typeof process !== 'undefined' && process.env) {
|
|
198
257
|
const prefix = this.config.envPrefix;
|
|
199
258
|
for (const [envKey, envValue] of Object.entries(process.env)) {
|
|
200
259
|
if (envKey?.startsWith(prefix) && envValue !== undefined) {
|
|
201
|
-
// Parse toggle key: TOGGLELY_MY_FEATURE -> my-feature
|
|
202
260
|
const toggleKey = envKey
|
|
203
261
|
.slice(prefix.length)
|
|
204
262
|
.toLowerCase()
|
|
@@ -214,13 +272,47 @@
|
|
|
214
272
|
console.warn('[Togglely] Failed to load offline toggles:', error);
|
|
215
273
|
}
|
|
216
274
|
}
|
|
275
|
+
/**
|
|
276
|
+
* Load offline toggles from JSON file (async)
|
|
277
|
+
*/
|
|
278
|
+
async loadOfflineJsonFile(path) {
|
|
279
|
+
try {
|
|
280
|
+
if (typeof window !== 'undefined') {
|
|
281
|
+
// Browser - fetch the JSON file
|
|
282
|
+
const response = await fetch(path);
|
|
283
|
+
if (response.ok) {
|
|
284
|
+
const data = await response.json();
|
|
285
|
+
for (const [key, value] of Object.entries(data)) {
|
|
286
|
+
this.toggles.set(key, this.parseOfflineValue(value));
|
|
287
|
+
}
|
|
288
|
+
this.offlineTogglesLoaded = true;
|
|
289
|
+
console.log('[Togglely] Loaded offline toggles from JSON file:', path);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
else if (typeof require !== 'undefined') {
|
|
293
|
+
// Node.js - require the JSON file
|
|
294
|
+
const fs = require('fs');
|
|
295
|
+
const pathModule = require('path');
|
|
296
|
+
const fullPath = pathModule.resolve(path);
|
|
297
|
+
if (fs.existsSync(fullPath)) {
|
|
298
|
+
const data = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
|
|
299
|
+
for (const [key, value] of Object.entries(data)) {
|
|
300
|
+
this.toggles.set(key, this.parseOfflineValue(value));
|
|
301
|
+
}
|
|
302
|
+
this.offlineTogglesLoaded = true;
|
|
303
|
+
console.log('[Togglely] Loaded offline toggles from JSON file:', fullPath);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
console.warn('[Togglely] Failed to load offline JSON file:', error);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
217
311
|
getOfflineToggle(key) {
|
|
218
312
|
if (!this.config.offlineFallback)
|
|
219
313
|
return null;
|
|
220
|
-
// Try to get from already loaded offline toggles
|
|
221
314
|
const cached = this.toggles.get(key);
|
|
222
315
|
if (cached) {
|
|
223
|
-
// If we haven't emitted offline event yet, do it now
|
|
224
316
|
if (!this.state.isOffline) {
|
|
225
317
|
this.state.isOffline = true;
|
|
226
318
|
this.emit('offline');
|
|
@@ -230,30 +322,29 @@
|
|
|
230
322
|
return null;
|
|
231
323
|
}
|
|
232
324
|
parseOfflineValue(value) {
|
|
233
|
-
// Handle boolean strings
|
|
234
325
|
if (typeof value === 'string') {
|
|
235
326
|
const lower = value.toLowerCase();
|
|
236
327
|
if (lower === 'true')
|
|
237
328
|
return { value: true, enabled: true };
|
|
238
329
|
if (lower === 'false')
|
|
239
330
|
return { value: false, enabled: true };
|
|
240
|
-
// Try to parse as number
|
|
241
331
|
if (!isNaN(Number(value))) {
|
|
242
332
|
return { value: Number(value), enabled: true };
|
|
243
333
|
}
|
|
244
|
-
// Try to parse as JSON
|
|
245
334
|
try {
|
|
246
335
|
const parsed = JSON.parse(value);
|
|
247
336
|
return { value: parsed, enabled: true };
|
|
248
337
|
}
|
|
249
338
|
catch {
|
|
250
|
-
// Return as string
|
|
251
339
|
return { value, enabled: true };
|
|
252
340
|
}
|
|
253
341
|
}
|
|
254
342
|
return { value, enabled: true };
|
|
255
343
|
}
|
|
256
344
|
// ==================== Refresh / Polling ====================
|
|
345
|
+
/**
|
|
346
|
+
* Refresh all toggles from the server
|
|
347
|
+
*/
|
|
257
348
|
async refresh() {
|
|
258
349
|
try {
|
|
259
350
|
const params = new URLSearchParams();
|
|
@@ -261,17 +352,11 @@
|
|
|
261
352
|
params.set('apiKey', this.config.apiKey);
|
|
262
353
|
const brandKey = this.context.tenantId || this.context.brandKey;
|
|
263
354
|
if (brandKey)
|
|
264
|
-
params.set('
|
|
265
|
-
// Always send context if available (needed for targeting rules)
|
|
355
|
+
params.set('tenantId', String(brandKey));
|
|
266
356
|
if (Object.keys(this.context).length > 0) {
|
|
267
357
|
params.set('context', JSON.stringify(this.context));
|
|
268
358
|
}
|
|
269
|
-
const response = await this.fetchWithTimeout(`${this.config.baseUrl}/sdk/flags/${this.config.project}/${this.config.environment}?${params.toString()}`, {
|
|
270
|
-
headers: {
|
|
271
|
-
'Authorization': `Bearer ${this.config.apiKey}`,
|
|
272
|
-
'Content-Type': 'application/json'
|
|
273
|
-
}
|
|
274
|
-
});
|
|
359
|
+
const response = await this.fetchWithTimeout(`${this.config.baseUrl}/sdk/flags/${encodeURIComponent(this.config.project)}/${encodeURIComponent(this.config.environment)}?${params.toString()}`, { headers: { 'Content-Type': 'application/json' } });
|
|
275
360
|
if (!response.ok) {
|
|
276
361
|
throw new Error(`HTTP ${response.status}`);
|
|
277
362
|
}
|
|
@@ -286,7 +371,6 @@
|
|
|
286
371
|
this.state.isReady = true;
|
|
287
372
|
this.emit('ready');
|
|
288
373
|
}
|
|
289
|
-
// If we were offline, go online
|
|
290
374
|
if (this.state.isOffline) {
|
|
291
375
|
this.state.isOffline = false;
|
|
292
376
|
this.emit('online');
|
|
@@ -295,7 +379,6 @@
|
|
|
295
379
|
}
|
|
296
380
|
catch (error) {
|
|
297
381
|
this.state.lastError = error;
|
|
298
|
-
// If we have offline toggles, switch to offline mode
|
|
299
382
|
if (this.config.offlineFallback && this.offlineTogglesLoaded) {
|
|
300
383
|
if (!this.state.isOffline) {
|
|
301
384
|
this.state.isOffline = true;
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../../core/dist/index.esm.js","../src/index.ts"],"sourcesContent":["/**\n * Togglely Core SDK - Framework agnostic\n *\n * Supports offline fallback via environment variables\n */\n/**\n * Core Togglely Client\n */\nclass TogglelyClient {\n constructor(config) {\n this.toggles = new Map();\n this.context = {};\n this.state = {\n isReady: false,\n isOffline: false,\n lastError: null,\n lastFetch: null\n };\n this.eventHandlers = new Map();\n this.offlineTogglesLoaded = false;\n this.config = {\n timeout: 5000,\n offlineFallback: true,\n envPrefix: 'TOGGLELY_',\n autoFetch: true,\n ...config\n };\n // Initialize event handlers\n this.eventHandlers.set('ready', new Set());\n this.eventHandlers.set('update', new Set());\n this.eventHandlers.set('error', new Set());\n this.eventHandlers.set('offline', new Set());\n this.eventHandlers.set('online', new Set());\n // Load offline toggles first (if enabled)\n if (this.config.offlineFallback) {\n this.loadOfflineToggles();\n }\n // Initial fetch (if enabled)\n if (this.config.autoFetch) {\n this.refresh();\n }\n }\n // ==================== Event Handling ====================\n on(event, handler) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.add(handler);\n }\n return () => this.off(event, handler);\n }\n off(event, handler) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.delete(handler);\n }\n }\n emit(event) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.forEach(handler => handler({ ...this.state }));\n }\n }\n // ==================== Context ====================\n setContext(context) {\n this.context = { ...this.context, ...context };\n }\n getContext() {\n return { ...this.context };\n }\n clearContext() {\n this.context = {};\n }\n // ==================== State ====================\n getState() {\n return { ...this.state };\n }\n isReady() {\n return this.state.isReady;\n }\n isOffline() {\n return this.state.isOffline;\n }\n // ==================== Toggle Accessors ====================\n async isEnabled(key, defaultValue = false) {\n const value = await this.getValue(key);\n if (value === null)\n return defaultValue;\n return value.enabled && value.value === true;\n }\n async getString(key, defaultValue = '') {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n return String(value.value);\n }\n async getNumber(key, defaultValue = 0) {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n return Number(value.value);\n }\n async getJSON(key, defaultValue = {}) {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n if (typeof value.value === 'string') {\n try {\n return JSON.parse(value.value);\n }\n catch {\n return defaultValue;\n }\n }\n return value.value;\n }\n async getValue(key) {\n // Try cache first - but only if no context is set\n if (Object.keys(this.context).length === 0) {\n const cached = this.toggles.get(key);\n if (cached) {\n return cached;\n }\n }\n // Fetch from server\n try {\n const params = new URLSearchParams();\n const brandKey = this.context.tenantId || this.context.brandKey;\n if (brandKey)\n params.set('brandKey', String(brandKey));\n // Always send context if available (needed for targeting rules)\n if (Object.keys(this.context).length > 0) {\n params.set('context', JSON.stringify(this.context));\n }\n const query = params.toString() ? `?${params.toString()}` : '';\n const response = await this.fetchWithTimeout(`${this.config.baseUrl}/sdk/flags/${this.config.project}/${this.config.environment}/${key}${query}`, {\n headers: {\n 'Authorization': `Bearer ${this.config.apiKey}`,\n 'Content-Type': 'application/json'\n }\n });\n if (!response.ok) {\n if (response.status === 404) {\n return null;\n }\n throw new Error(`HTTP ${response.status}`);\n }\n const data = await response.json();\n this.toggles.set(key, data);\n // Update state if we were offline\n if (this.state.isOffline) {\n this.state.isOffline = false;\n this.emit('online');\n }\n return data;\n }\n catch (error) {\n // Try offline fallback\n const offlineValue = this.getOfflineToggle(key);\n if (offlineValue !== null) {\n return offlineValue;\n }\n console.error(`[Togglely] Failed to fetch toggle \"${key}\":`, error);\n return null;\n }\n }\n getAllToggles() {\n const result = {};\n this.toggles.forEach((value, key) => {\n result[key] = value;\n });\n return result;\n }\n // ==================== Offline Fallback ====================\n /**\n * Load toggles from environment variables\n * Format: TOGGLELY_<TOGGLE_KEY>=<value> or TOGGLELY_<TOGGLE_KEY>_ENABLED=true\n */\n loadOfflineToggles() {\n try {\n // Browser environment - check window.__TOGGLELY_TOGGLES\n if (typeof window !== 'undefined' && window.__TOGGLELY_TOGGLES) {\n const offlineToggles = window.__TOGGLELY_TOGGLES;\n for (const [key, value] of Object.entries(offlineToggles)) {\n this.toggles.set(key, this.parseOfflineValue(value));\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from window.__TOGGLELY_TOGGLES');\n return;\n }\n // Node.js / Bun / Deno environment - check process.env\n if (typeof process !== 'undefined' && process.env) {\n const prefix = this.config.envPrefix;\n for (const [envKey, envValue] of Object.entries(process.env)) {\n if (envKey?.startsWith(prefix) && envValue !== undefined) {\n // Parse toggle key: TOGGLELY_MY_FEATURE -> my-feature\n const toggleKey = envKey\n .slice(prefix.length)\n .toLowerCase()\n .replace(/_/g, '-');\n this.toggles.set(toggleKey, this.parseOfflineValue(envValue));\n }\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from environment variables');\n }\n }\n catch (error) {\n console.warn('[Togglely] Failed to load offline toggles:', error);\n }\n }\n getOfflineToggle(key) {\n if (!this.config.offlineFallback)\n return null;\n // Try to get from already loaded offline toggles\n const cached = this.toggles.get(key);\n if (cached) {\n // If we haven't emitted offline event yet, do it now\n if (!this.state.isOffline) {\n this.state.isOffline = true;\n this.emit('offline');\n }\n return cached;\n }\n return null;\n }\n parseOfflineValue(value) {\n // Handle boolean strings\n if (typeof value === 'string') {\n const lower = value.toLowerCase();\n if (lower === 'true')\n return { value: true, enabled: true };\n if (lower === 'false')\n return { value: false, enabled: true };\n // Try to parse as number\n if (!isNaN(Number(value))) {\n return { value: Number(value), enabled: true };\n }\n // Try to parse as JSON\n try {\n const parsed = JSON.parse(value);\n return { value: parsed, enabled: true };\n }\n catch {\n // Return as string\n return { value, enabled: true };\n }\n }\n return { value, enabled: true };\n }\n // ==================== Refresh / Polling ====================\n async refresh() {\n try {\n const params = new URLSearchParams();\n if (this.config.apiKey)\n params.set('apiKey', this.config.apiKey);\n const brandKey = this.context.tenantId || this.context.brandKey;\n if (brandKey)\n params.set('brandKey', String(brandKey));\n // Always send context if available (needed for targeting rules)\n if (Object.keys(this.context).length > 0) {\n params.set('context', JSON.stringify(this.context));\n }\n const response = await this.fetchWithTimeout(`${this.config.baseUrl}/sdk/flags/${this.config.project}/${this.config.environment}?${params.toString()}`, {\n headers: {\n 'Authorization': `Bearer ${this.config.apiKey}`,\n 'Content-Type': 'application/json'\n }\n });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n const data = await response.json();\n this.toggles.clear();\n for (const [key, value] of Object.entries(data)) {\n this.toggles.set(key, value);\n }\n this.state.lastFetch = new Date();\n this.state.lastError = null;\n if (!this.state.isReady) {\n this.state.isReady = true;\n this.emit('ready');\n }\n // If we were offline, go online\n if (this.state.isOffline) {\n this.state.isOffline = false;\n this.emit('online');\n }\n this.emit('update');\n }\n catch (error) {\n this.state.lastError = error;\n // If we have offline toggles, switch to offline mode\n if (this.config.offlineFallback && this.offlineTogglesLoaded) {\n if (!this.state.isOffline) {\n this.state.isOffline = true;\n this.emit('offline');\n }\n }\n this.emit('error');\n console.error('[Togglely] Failed to refresh toggles:', error);\n }\n }\n forceOfflineMode() {\n this.state.isOffline = true;\n this.emit('offline');\n }\n forceOnlineMode() {\n this.state.isOffline = false;\n this.refresh();\n this.emit('online');\n }\n // ==================== Cleanup ====================\n destroy() {\n this.toggles.clear();\n this.eventHandlers.forEach(handlers => handlers.clear());\n }\n // ==================== Private Helpers ====================\n fetchWithTimeout(url, options) {\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n reject(new Error('Request timeout'));\n }, this.config.timeout);\n fetch(url, options)\n .then(response => {\n clearTimeout(timeoutId);\n resolve(response);\n })\n .catch(error => {\n clearTimeout(timeoutId);\n reject(error);\n });\n });\n }\n}\n// ==================== Utility Functions ====================\n/**\n * Create a client-side toggle loader script\n * Use this to inject offline toggles into your HTML\n */\nfunction createOfflineTogglesScript(toggles) {\n return `<script>window.__TOGGLELY_TOGGLES = ${JSON.stringify(toggles)};</script>`;\n}\n/**\n * Helper to convert toggles to environment variables\n */\nfunction togglesToEnvVars(toggles, prefix = 'TOGGLELY_') {\n const envVars = {};\n for (const [key, value] of Object.entries(toggles)) {\n const envKey = prefix + key.toUpperCase().replace(/-/g, '_');\n envVars[envKey] = typeof value === 'object' ? JSON.stringify(value) : String(value);\n }\n return envVars;\n}\n\nexport { TogglelyClient, createOfflineTogglesScript, TogglelyClient as default, togglesToEnvVars };\n//# sourceMappingURL=index.esm.js.map\n",null],"names":[],"mappings":";;;;;;IAAA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,MAAM,cAAc,CAAC;IACrB,IAAI,WAAW,CAAC,MAAM,EAAE;IACxB,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE;IAChC,QAAQ,IAAI,CAAC,OAAO,GAAG,EAAE;IACzB,QAAQ,IAAI,CAAC,KAAK,GAAG;IACrB,YAAY,OAAO,EAAE,KAAK;IAC1B,YAAY,SAAS,EAAE,KAAK;IAC5B,YAAY,SAAS,EAAE,IAAI;IAC3B,YAAY,SAAS,EAAE;IACvB,SAAS;IACT,QAAQ,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE;IACtC,QAAQ,IAAI,CAAC,oBAAoB,GAAG,KAAK;IACzC,QAAQ,IAAI,CAAC,MAAM,GAAG;IACtB,YAAY,OAAO,EAAE,IAAI;IACzB,YAAY,eAAe,EAAE,IAAI;IACjC,YAAY,SAAS,EAAE,WAAW;IAClC,YAAY,SAAS,EAAE,IAAI;IAC3B,YAAY,GAAG;IACf,SAAS;IACT;IACA,QAAQ,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC;IAClD,QAAQ,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,GAAG,EAAE,CAAC;IACnD,QAAQ,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC;IAClD,QAAQ,IAAI,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"}
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../../core/dist/index.esm.js","../src/index.ts"],"sourcesContent":["/**\n * Togglely Core SDK - Framework agnostic feature flag management\n *\n * Features:\n * - Real-time feature flag evaluation\n * - Offline fallback via JSON file, environment variables, or window object\n * - Multi-brand/tenant support\n * - Type-safe flag access\n * - Build-time JSON generation for offline-first deployment\n */\n// ==================== Togglely Client ====================\nclass TogglelyClient {\n constructor(config) {\n this.toggles = new Map();\n this.context = {};\n this.state = {\n isReady: false,\n isOffline: false,\n lastError: null,\n lastFetch: null\n };\n this.eventHandlers = new Map();\n this.offlineTogglesLoaded = false;\n this.config = {\n timeout: 5000,\n offlineFallback: true,\n envPrefix: 'TOGGLELY_',\n autoFetch: true,\n offlineJsonPath: undefined,\n ...config\n };\n // Initialize event handlers\n this.eventHandlers.set('ready', new Set());\n this.eventHandlers.set('update', new Set());\n this.eventHandlers.set('error', new Set());\n this.eventHandlers.set('offline', new Set());\n this.eventHandlers.set('online', new Set());\n // Set initial context if provided (including brandKey/tenantId)\n const initialContext = { ...config.context };\n if (config.brandKey)\n initialContext.brandKey = config.brandKey;\n if (config.tenantId)\n initialContext.tenantId = config.tenantId;\n this.context = initialContext;\n // Load offline toggles first (if enabled)\n if (this.config.offlineFallback) {\n this.loadOfflineToggles();\n }\n // Initial fetch (if enabled)\n if (this.config.autoFetch) {\n this.refresh();\n }\n }\n // ==================== Event Handling ====================\n on(event, handler) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.add(handler);\n }\n return () => this.off(event, handler);\n }\n off(event, handler) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.delete(handler);\n }\n }\n emit(event) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.forEach(handler => handler({ ...this.state }));\n }\n }\n // ==================== Context ====================\n setContext(context) {\n this.context = { ...this.context, ...context };\n }\n getContext() {\n return { ...this.context };\n }\n clearContext() {\n this.context = {};\n }\n // ==================== State ====================\n getState() {\n return { ...this.state };\n }\n isReady() {\n return this.state.isReady;\n }\n isOffline() {\n return this.state.isOffline;\n }\n // ==================== Toggle Accessors ====================\n /**\n * Check if a boolean feature flag is enabled\n * @param key - The flag key\n * @param defaultValue - Default value if flag not found\n * @returns Promise<boolean>\n */\n async isEnabled(key, defaultValue = false) {\n const value = await this.getValue(key);\n if (value === null) {\n return defaultValue;\n }\n return value.enabled && value.value === true;\n }\n /**\n * Get a string feature flag value\n * @param key - The flag key\n * @param defaultValue - Default value if flag not found or disabled\n * @returns Promise<string>\n */\n async getString(key, defaultValue = '') {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n return String(value.value);\n }\n /**\n * Get a number feature flag value\n * @param key - The flag key\n * @param defaultValue - Default value if flag not found or disabled\n * @returns Promise<number>\n */\n async getNumber(key, defaultValue = 0) {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n return Number(value.value);\n }\n /**\n * Get a JSON feature flag value\n * @param key - The flag key\n * @param defaultValue - Default value if flag not found or disabled\n * @returns Promise<T>\n */\n async getJSON(key, defaultValue = {}) {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n if (typeof value.value === 'string') {\n try {\n return JSON.parse(value.value);\n }\n catch {\n return defaultValue;\n }\n }\n return value.value;\n }\n /**\n * Get raw toggle value\n * @param key - The flag key\n * @returns Promise<ToggleValue | null>\n */\n async getValue(key) {\n // Try cache first - but only if no context is set\n if (Object.keys(this.context).length === 0) {\n const cached = this.toggles.get(key);\n if (cached) {\n return cached;\n }\n }\n // Fetch from server\n try {\n const params = new URLSearchParams();\n if (this.config.apiKey)\n params.set('apiKey', this.config.apiKey);\n const brandKey = this.context.tenantId || this.context.brandKey;\n if (brandKey)\n params.set('tenantId', String(brandKey));\n if (Object.keys(this.context).length > 0) {\n params.set('context', JSON.stringify(this.context));\n }\n const query = params.toString() ? `?${params.toString()}` : '';\n const url = `${this.config.baseUrl}/sdk/flags/${encodeURIComponent(this.config.project)}/${encodeURIComponent(this.config.environment)}/${encodeURIComponent(key)}${query}`;\n const response = await this.fetchWithTimeout(url, { headers: { 'Content-Type': 'application/json' } });\n if (!response.ok) {\n if (response.status === 404) {\n return null;\n }\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n const data = await response.json();\n this.toggles.set(key, data);\n if (this.state.isOffline) {\n this.state.isOffline = false;\n this.emit('online');\n }\n return data;\n }\n catch (error) {\n // Try offline fallback\n if (this.config.offlineFallback) {\n const offlineValue = this.getOfflineToggle(key);\n if (offlineValue !== null) {\n return offlineValue;\n }\n }\n // Return safe default\n return { value: false, enabled: false };\n }\n }\n /**\n * Get all toggles\n * @returns Record<string, ToggleValue>\n */\n getAllToggles() {\n const result = {};\n this.toggles.forEach((value, key) => {\n result[key] = value;\n });\n return result;\n }\n // ==================== Offline Fallback ====================\n /**\n * Load offline toggles from multiple sources (in priority order):\n * 1. Inline offlineToggles from config\n * 2. JSON file (if offlineJsonPath is set)\n * 3. window.__TOGGLELY_TOGGLES (browser)\n * 4. Environment variables (Node.js)\n */\n loadOfflineToggles() {\n try {\n // Priority 1: Inline offline toggles from config\n if (this.config.offlineToggles && Object.keys(this.config.offlineToggles).length > 0) {\n for (const [key, value] of Object.entries(this.config.offlineToggles)) {\n this.toggles.set(key, value);\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from config');\n return;\n }\n // Priority 2: JSON file (browser only - fetch synchronously not possible, will try async)\n if (this.config.offlineJsonPath && typeof window !== 'undefined') {\n this.loadOfflineJsonFile(this.config.offlineJsonPath);\n }\n // Priority 3: Browser environment - check window.__TOGGLELY_TOGGLES\n if (typeof window !== 'undefined' && window.__TOGGLELY_TOGGLES) {\n const offlineToggles = window.__TOGGLELY_TOGGLES;\n for (const [key, value] of Object.entries(offlineToggles)) {\n this.toggles.set(key, this.parseOfflineValue(value));\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from window.__TOGGLELY_TOGGLES');\n return;\n }\n // Priority 4: Node.js / Bun / Deno environment - check process.env\n if (typeof process !== 'undefined' && process.env) {\n const prefix = this.config.envPrefix;\n for (const [envKey, envValue] of Object.entries(process.env)) {\n if (envKey?.startsWith(prefix) && envValue !== undefined) {\n const toggleKey = envKey\n .slice(prefix.length)\n .toLowerCase()\n .replace(/_/g, '-');\n this.toggles.set(toggleKey, this.parseOfflineValue(envValue));\n }\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from environment variables');\n }\n }\n catch (error) {\n console.warn('[Togglely] Failed to load offline toggles:', error);\n }\n }\n /**\n * Load offline toggles from JSON file (async)\n */\n async loadOfflineJsonFile(path) {\n try {\n if (typeof window !== 'undefined') {\n // Browser - fetch the JSON file\n const response = await fetch(path);\n if (response.ok) {\n const data = await response.json();\n for (const [key, value] of Object.entries(data)) {\n this.toggles.set(key, this.parseOfflineValue(value));\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from JSON file:', path);\n }\n }\n else if (typeof require !== 'undefined') {\n // Node.js - require the JSON file\n const fs = require('fs');\n const pathModule = require('path');\n const fullPath = pathModule.resolve(path);\n if (fs.existsSync(fullPath)) {\n const data = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));\n for (const [key, value] of Object.entries(data)) {\n this.toggles.set(key, this.parseOfflineValue(value));\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from JSON file:', fullPath);\n }\n }\n }\n catch (error) {\n console.warn('[Togglely] Failed to load offline JSON file:', error);\n }\n }\n getOfflineToggle(key) {\n if (!this.config.offlineFallback)\n return null;\n const cached = this.toggles.get(key);\n if (cached) {\n if (!this.state.isOffline) {\n this.state.isOffline = true;\n this.emit('offline');\n }\n return cached;\n }\n return null;\n }\n parseOfflineValue(value) {\n if (typeof value === 'string') {\n const lower = value.toLowerCase();\n if (lower === 'true')\n return { value: true, enabled: true };\n if (lower === 'false')\n return { value: false, enabled: true };\n if (!isNaN(Number(value))) {\n return { value: Number(value), enabled: true };\n }\n try {\n const parsed = JSON.parse(value);\n return { value: parsed, enabled: true };\n }\n catch {\n return { value, enabled: true };\n }\n }\n return { value, enabled: true };\n }\n // ==================== Refresh / Polling ====================\n /**\n * Refresh all toggles from the server\n */\n async refresh() {\n try {\n const params = new URLSearchParams();\n if (this.config.apiKey)\n params.set('apiKey', this.config.apiKey);\n const brandKey = this.context.tenantId || this.context.brandKey;\n if (brandKey)\n params.set('tenantId', String(brandKey));\n if (Object.keys(this.context).length > 0) {\n params.set('context', JSON.stringify(this.context));\n }\n const response = await this.fetchWithTimeout(`${this.config.baseUrl}/sdk/flags/${encodeURIComponent(this.config.project)}/${encodeURIComponent(this.config.environment)}?${params.toString()}`, { headers: { 'Content-Type': 'application/json' } });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n const data = await response.json();\n this.toggles.clear();\n for (const [key, value] of Object.entries(data)) {\n this.toggles.set(key, value);\n }\n this.state.lastFetch = new Date();\n this.state.lastError = null;\n if (!this.state.isReady) {\n this.state.isReady = true;\n this.emit('ready');\n }\n if (this.state.isOffline) {\n this.state.isOffline = false;\n this.emit('online');\n }\n this.emit('update');\n }\n catch (error) {\n this.state.lastError = error;\n if (this.config.offlineFallback && this.offlineTogglesLoaded) {\n if (!this.state.isOffline) {\n this.state.isOffline = true;\n this.emit('offline');\n }\n }\n this.emit('error');\n console.error('[Togglely] Failed to refresh toggles:', error);\n }\n }\n forceOfflineMode() {\n this.state.isOffline = true;\n this.emit('offline');\n }\n forceOnlineMode() {\n this.state.isOffline = false;\n this.refresh();\n this.emit('online');\n }\n // ==================== Cleanup ====================\n destroy() {\n this.toggles.clear();\n this.eventHandlers.forEach(handlers => handlers.clear());\n }\n // ==================== Private Helpers ====================\n fetchWithTimeout(url, options) {\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n reject(new Error('Request timeout'));\n }, this.config.timeout);\n fetch(url, options)\n .then(response => {\n clearTimeout(timeoutId);\n resolve(response);\n })\n .catch(error => {\n clearTimeout(timeoutId);\n reject(error);\n });\n });\n }\n}\n// ==================== Utility Functions ====================\n/**\n * Create a client-side toggle loader script\n * Use this to inject offline toggles into your HTML\n */\nfunction createOfflineTogglesScript(toggles) {\n return `<script>window.__TOGGLELY_TOGGLES = ${JSON.stringify(toggles)};</script>`;\n}\n/**\n * Helper to convert toggles to environment variables\n */\nfunction togglesToEnvVars(toggles, prefix = 'TOGGLELY_') {\n const envVars = {};\n for (const [key, value] of Object.entries(toggles)) {\n const envKey = prefix + key.toUpperCase().replace(/-/g, '_');\n envVars[envKey] = typeof value === 'object' ? JSON.stringify(value) : String(value);\n }\n return envVars;\n}\n\nexport { TogglelyClient, createOfflineTogglesScript, TogglelyClient as default, togglesToEnvVars };\n//# sourceMappingURL=index.esm.js.map\n",null],"names":[],"mappings":";;;;;;IAAA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,MAAM,cAAc,CAAC;IACrB,IAAI,WAAW,CAAC,MAAM,EAAE;IACxB,QAAQ,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE;IAChC,QAAQ,IAAI,CAAC,OAAO,GAAG,EAAE;IACzB,QAAQ,IAAI,CAAC,KAAK,GAAG;IACrB,YAAY,OAAO,EAAE,KAAK;IAC1B,YAAY,SAAS,EAAE,KAAK;IAC5B,YAAY,SAAS,EAAE,IAAI;IAC3B,YAAY,SAAS,EAAE;IACvB,SAAS;IACT,QAAQ,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE;IACtC,QAAQ,IAAI,CAAC,oBAAoB,GAAG,KAAK;IACzC,QAAQ,IAAI,CAAC,MAAM,GAAG;IACtB,YAAY,OAAO,EAAE,IAAI;IACzB,YAAY,eAAe,EAAE,IAAI;IACjC,YAAY,SAAS,EAAE,WAAW;IAClC,YAAY,SAAS,EAAE,IAAI;IAC3B,YAAY,eAAe,EAAE,SAAS;IACtC,YAAY,GAAG;IACf,SAAS;IACT;IAC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AM,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK;gBAChC;gBAEA,MAAM,eAAe,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,YAAY,CAAC;IACvE,YAAA,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,eAAe,GAAG,eAAe;IAE9D,YAAA,SAAS,CAAC,OAAO,CAAC,QAAQ,IAAG;oBAC3B,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC;IACpD,gBAAA,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAG;IACnB,oBAAA,EAAkB,CAAC,KAAK,CAAC,OAAO,GAAG,UAAU,GAAG,EAAE,GAAG,MAAM;IAC9D,gBAAA,CAAC,CAAC;IACJ,YAAA,CAAC,CAAC;YACJ;IACF,IAAA,CAAC;;IAGD,IAAA,SAAS,EAAE;;QAGX,MAAM,WAAW,GAAG,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC;IAElD,IAAA,OAAO,WAAW;IACpB;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.umd.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Flagify={})}(this,function(e){"use strict";class t{constructor(e){this.toggles=new Map,this.context={},this.state={isReady:!1,isOffline:!1,lastError:null,lastFetch:null},this.eventHandlers=new Map,this.offlineTogglesLoaded=!1,this.config={timeout:5e3,offlineFallback:!0,envPrefix:"TOGGLELY_",autoFetch:!0,...e},this.eventHandlers.set("ready",new Set),this.eventHandlers.set("update",new Set),this.eventHandlers.set("error",new Set),this.eventHandlers.set("offline",new Set),this.eventHandlers.set("online",new Set),this.config.offlineFallback&&this.loadOfflineToggles(),this.config.autoFetch&&this.refresh()}on(e,t){const n=this.eventHandlers.get(e);return n&&n.add(t),()=>this.off(e,t)}off(e,t){const n=this.eventHandlers.get(e);n&&n.delete(t)}emit(e){const t=this.eventHandlers.get(e);t&&t.forEach(e=>e({...this.state}))}setContext(e){this.context={...this.context,...e}}getContext(){return{...this.context}}clearContext(){this.context={}}getState(){return{...this.state}}isReady(){return this.state.isReady}isOffline(){return this.state.isOffline}async isEnabled(e,t=!1){const n=await this.getValue(e);return null===n?t:n.enabled&&!0===n.value}async getString(e,t=""){const n=await this.getValue(e);return null!==n&&n.enabled?String(n.value):t}async getNumber(e,t=0){const n=await this.getValue(e);return null!==n&&n.enabled?Number(n.value):t}async getJSON(e,t={}){const n=await this.getValue(e);if(null===n||!n.enabled)return t;if("string"==typeof n.value)try{return JSON.parse(n.value)}catch{return t}return n.value}async getValue(e){if(0===Object.keys(this.context).length){const t=this.toggles.get(e);if(t)return t}try{const t=new URLSearchParams,n=this.context.tenantId||this.context.brandKey;n&&t.set("
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Flagify={})}(this,function(e){"use strict";class t{constructor(e){this.toggles=new Map,this.context={},this.state={isReady:!1,isOffline:!1,lastError:null,lastFetch:null},this.eventHandlers=new Map,this.offlineTogglesLoaded=!1,this.config={timeout:5e3,offlineFallback:!0,envPrefix:"TOGGLELY_",autoFetch:!0,offlineJsonPath:void 0,...e},this.eventHandlers.set("ready",new Set),this.eventHandlers.set("update",new Set),this.eventHandlers.set("error",new Set),this.eventHandlers.set("offline",new Set),this.eventHandlers.set("online",new Set);const t={...e.context};e.brandKey&&(t.brandKey=e.brandKey),e.tenantId&&(t.tenantId=e.tenantId),this.context=t,this.config.offlineFallback&&this.loadOfflineToggles(),this.config.autoFetch&&this.refresh()}on(e,t){const n=this.eventHandlers.get(e);return n&&n.add(t),()=>this.off(e,t)}off(e,t){const n=this.eventHandlers.get(e);n&&n.delete(t)}emit(e){const t=this.eventHandlers.get(e);t&&t.forEach(e=>e({...this.state}))}setContext(e){this.context={...this.context,...e}}getContext(){return{...this.context}}clearContext(){this.context={}}getState(){return{...this.state}}isReady(){return this.state.isReady}isOffline(){return this.state.isOffline}async isEnabled(e,t=!1){const n=await this.getValue(e);return null===n?t:n.enabled&&!0===n.value}async getString(e,t=""){const n=await this.getValue(e);return null!==n&&n.enabled?String(n.value):t}async getNumber(e,t=0){const n=await this.getValue(e);return null!==n&&n.enabled?Number(n.value):t}async getJSON(e,t={}){const n=await this.getValue(e);if(null===n||!n.enabled)return t;if("string"==typeof n.value)try{return JSON.parse(n.value)}catch{return t}return n.value}async getValue(e){if(0===Object.keys(this.context).length){const t=this.toggles.get(e);if(t)return t}try{const t=new URLSearchParams;this.config.apiKey&&t.set("apiKey",this.config.apiKey);const n=this.context.tenantId||this.context.brandKey;n&&t.set("tenantId",String(n)),Object.keys(this.context).length>0&&t.set("context",JSON.stringify(this.context));const o=t.toString()?`?${t.toString()}`:"",s=`${this.config.baseUrl}/sdk/flags/${encodeURIComponent(this.config.project)}/${encodeURIComponent(this.config.environment)}/${encodeURIComponent(e)}${o}`,i=await this.fetchWithTimeout(s,{headers:{"Content-Type":"application/json"}});if(!i.ok){if(404===i.status)return null;throw new Error(`HTTP ${i.status}: ${i.statusText}`)}const l=await i.json();return this.toggles.set(e,l),this.state.isOffline&&(this.state.isOffline=!1,this.emit("online")),l}catch(t){if(this.config.offlineFallback){const t=this.getOfflineToggle(e);if(null!==t)return t}return{value:!1,enabled:!1}}}getAllToggles(){const e={};return this.toggles.forEach((t,n)=>{e[n]=t}),e}loadOfflineToggles(){try{if(this.config.offlineToggles&&Object.keys(this.config.offlineToggles).length>0){for(const[e,t]of Object.entries(this.config.offlineToggles))this.toggles.set(e,t);return this.offlineTogglesLoaded=!0,void console.log("[Togglely] Loaded offline toggles from config")}if(this.config.offlineJsonPath&&"undefined"!=typeof window&&this.loadOfflineJsonFile(this.config.offlineJsonPath),"undefined"!=typeof window&&window.__TOGGLELY_TOGGLES){const e=window.__TOGGLELY_TOGGLES;for(const[t,n]of Object.entries(e))this.toggles.set(t,this.parseOfflineValue(n));return this.offlineTogglesLoaded=!0,void console.log("[Togglely] Loaded offline toggles from window.__TOGGLELY_TOGGLES")}if("undefined"!=typeof process&&process.env){const e=this.config.envPrefix;for(const[t,n]of Object.entries(process.env))if(t?.startsWith(e)&&void 0!==n){const o=t.slice(e.length).toLowerCase().replace(/_/g,"-");this.toggles.set(o,this.parseOfflineValue(n))}this.offlineTogglesLoaded=!0,console.log("[Togglely] Loaded offline toggles from environment variables")}}catch(e){console.warn("[Togglely] Failed to load offline toggles:",e)}}async loadOfflineJsonFile(e){try{if("undefined"!=typeof window){const t=await fetch(e);if(t.ok){const n=await t.json();for(const[e,t]of Object.entries(n))this.toggles.set(e,this.parseOfflineValue(t));this.offlineTogglesLoaded=!0,console.log("[Togglely] Loaded offline toggles from JSON file:",e)}}else if("undefined"!=typeof require){const t=require("fs"),n=require("path").resolve(e);if(t.existsSync(n)){const e=JSON.parse(t.readFileSync(n,"utf-8"));for(const[t,n]of Object.entries(e))this.toggles.set(t,this.parseOfflineValue(n));this.offlineTogglesLoaded=!0,console.log("[Togglely] Loaded offline toggles from JSON file:",n)}}}catch(e){console.warn("[Togglely] Failed to load offline JSON file:",e)}}getOfflineToggle(e){if(!this.config.offlineFallback)return null;const t=this.toggles.get(e);return t?(this.state.isOffline||(this.state.isOffline=!0,this.emit("offline")),t):null}parseOfflineValue(e){if("string"==typeof e){const t=e.toLowerCase();if("true"===t)return{value:!0,enabled:!0};if("false"===t)return{value:!1,enabled:!0};if(!isNaN(Number(e)))return{value:Number(e),enabled:!0};try{return{value:JSON.parse(e),enabled:!0}}catch{return{value:e,enabled:!0}}}return{value:e,enabled:!0}}async refresh(){try{const e=new URLSearchParams;this.config.apiKey&&e.set("apiKey",this.config.apiKey);const t=this.context.tenantId||this.context.brandKey;t&&e.set("tenantId",String(t)),Object.keys(this.context).length>0&&e.set("context",JSON.stringify(this.context));const n=await this.fetchWithTimeout(`${this.config.baseUrl}/sdk/flags/${encodeURIComponent(this.config.project)}/${encodeURIComponent(this.config.environment)}?${e.toString()}`,{headers:{"Content-Type":"application/json"}});if(!n.ok)throw new Error(`HTTP ${n.status}`);const o=await n.json();this.toggles.clear();for(const[e,t]of Object.entries(o))this.toggles.set(e,t);this.state.lastFetch=new Date,this.state.lastError=null,this.state.isReady||(this.state.isReady=!0,this.emit("ready")),this.state.isOffline&&(this.state.isOffline=!1,this.emit("online")),this.emit("update")}catch(e){this.state.lastError=e,this.config.offlineFallback&&this.offlineTogglesLoaded&&(this.state.isOffline||(this.state.isOffline=!0,this.emit("offline"))),this.emit("error"),console.error("[Togglely] Failed to refresh toggles:",e)}}forceOfflineMode(){this.state.isOffline=!0,this.emit("offline")}forceOnlineMode(){this.state.isOffline=!1,this.refresh(),this.emit("online")}destroy(){this.toggles.clear(),this.eventHandlers.forEach(e=>e.clear())}fetchWithTimeout(e,t){return new Promise((n,o)=>{const s=setTimeout(()=>{o(new Error("Request timeout"))},this.config.timeout);fetch(e,t).then(e=>{clearTimeout(s),n(e)}).catch(e=>{clearTimeout(s),o(e)})})}}function n(){return"undefined"!=typeof window&&window.togglely||null}e.TogglelyClient=t,e.createOfflineTogglesScript=function(e){return`<script>window.__TOGGLELY_TOGGLES = ${JSON.stringify(e)};<\/script>`},e.default=t,e.getGlobalTogglely=n,e.getJSON=async function(e,t={}){const o=n();return o?o.getJSON(e,t):(console.error("[Togglely] No global instance found. Call initTogglely() first."),t)},e.getNumber=async function(e,t=0){const o=n();return o?o.getNumber(e,t):(console.error("[Togglely] No global instance found. Call initTogglely() first."),t)},e.getString=async function(e,t=""){const o=n();return o?o.getString(e,t):(console.error("[Togglely] No global instance found. Call initTogglely() first."),t)},e.initTogglely=function(e){const n=new t(e);return"undefined"!=typeof window&&(window.togglely=n),n},e.isEnabled=async function(e,t=!1){const o=n();return o?o.isEnabled(e,t):(console.error("[Togglely] No global instance found. Call initTogglely() first."),t)},e.togglelyInit=function(e){const t=n();if(!t)return console.error("[Togglely] No global instance found. Call initTogglely() first."),()=>{};const o=async()=>{for(const[n,o]of Object.entries(e)){let e,s=!1,i=!1;"string"==typeof o?e=[o]:Array.isArray(o)?e=o:(e=[o.selector],s=o.defaultValue??!1,i=o.invert??!1);const l=await t.isEnabled(n,s),r=i?!l:l;e.forEach(e=>{document.querySelectorAll(e).forEach(e=>{e.style.display=r?"":"none"})})}};return o(),t.on("update",o)},e.togglelyToggle=async function(e,t,o={}){const{defaultValue:s=!1,invert:i=!1,hideClass:l="togglely-hidden",showClass:r="togglely-visible"}=o,a=n();if(!a)return void console.error("[Togglely] No global instance found. Call initTogglely() first.");const f=await a.isEnabled(t,s),c=i?!f:f;document.querySelectorAll(e).forEach(e=>{c?(e.classList.remove(l),e.classList.add(r),e.style.display=""):(e.classList.remove(r),e.classList.add(l),e.style.display="none")})},e.togglesToEnvVars=function(e,t="TOGGLELY_"){const n={};for(const[o,s]of Object.entries(e)){n[t+o.toUpperCase().replace(/-/g,"_")]="object"==typeof s?JSON.stringify(s):String(s)}return n},Object.defineProperty(e,"__esModule",{value:!0})});
|
|
2
2
|
//# sourceMappingURL=index.umd.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.min.js","sources":["../../core/dist/index.esm.js","../src/index.ts"],"sourcesContent":["/**\n * Togglely Core SDK - Framework agnostic\n *\n * Supports offline fallback via environment variables\n */\n/**\n * Core Togglely Client\n */\nclass TogglelyClient {\n constructor(config) {\n this.toggles = new Map();\n this.context = {};\n this.state = {\n isReady: false,\n isOffline: false,\n lastError: null,\n lastFetch: null\n };\n this.eventHandlers = new Map();\n this.offlineTogglesLoaded = false;\n this.config = {\n timeout: 5000,\n offlineFallback: true,\n envPrefix: 'TOGGLELY_',\n autoFetch: true,\n ...config\n };\n // Initialize event handlers\n this.eventHandlers.set('ready', new Set());\n this.eventHandlers.set('update', new Set());\n this.eventHandlers.set('error', new Set());\n this.eventHandlers.set('offline', new Set());\n this.eventHandlers.set('online', new Set());\n // Load offline toggles first (if enabled)\n if (this.config.offlineFallback) {\n this.loadOfflineToggles();\n }\n // Initial fetch (if enabled)\n if (this.config.autoFetch) {\n this.refresh();\n }\n }\n // ==================== Event Handling ====================\n on(event, handler) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.add(handler);\n }\n return () => this.off(event, handler);\n }\n off(event, handler) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.delete(handler);\n }\n }\n emit(event) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.forEach(handler => handler({ ...this.state }));\n }\n }\n // ==================== Context ====================\n setContext(context) {\n this.context = { ...this.context, ...context };\n }\n getContext() {\n return { ...this.context };\n }\n clearContext() {\n this.context = {};\n }\n // ==================== State ====================\n getState() {\n return { ...this.state };\n }\n isReady() {\n return this.state.isReady;\n }\n isOffline() {\n return this.state.isOffline;\n }\n // ==================== Toggle Accessors ====================\n async isEnabled(key, defaultValue = false) {\n const value = await this.getValue(key);\n if (value === null)\n return defaultValue;\n return value.enabled && value.value === true;\n }\n async getString(key, defaultValue = '') {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n return String(value.value);\n }\n async getNumber(key, defaultValue = 0) {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n return Number(value.value);\n }\n async getJSON(key, defaultValue = {}) {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n if (typeof value.value === 'string') {\n try {\n return JSON.parse(value.value);\n }\n catch {\n return defaultValue;\n }\n }\n return value.value;\n }\n async getValue(key) {\n // Try cache first - but only if no context is set\n if (Object.keys(this.context).length === 0) {\n const cached = this.toggles.get(key);\n if (cached) {\n return cached;\n }\n }\n // Fetch from server\n try {\n const params = new URLSearchParams();\n const brandKey = this.context.tenantId || this.context.brandKey;\n if (brandKey)\n params.set('brandKey', String(brandKey));\n // Always send context if available (needed for targeting rules)\n if (Object.keys(this.context).length > 0) {\n params.set('context', JSON.stringify(this.context));\n }\n const query = params.toString() ? `?${params.toString()}` : '';\n const response = await this.fetchWithTimeout(`${this.config.baseUrl}/sdk/flags/${this.config.project}/${this.config.environment}/${key}${query}`, {\n headers: {\n 'Authorization': `Bearer ${this.config.apiKey}`,\n 'Content-Type': 'application/json'\n }\n });\n if (!response.ok) {\n if (response.status === 404) {\n return null;\n }\n throw new Error(`HTTP ${response.status}`);\n }\n const data = await response.json();\n this.toggles.set(key, data);\n // Update state if we were offline\n if (this.state.isOffline) {\n this.state.isOffline = false;\n this.emit('online');\n }\n return data;\n }\n catch (error) {\n // Try offline fallback\n const offlineValue = this.getOfflineToggle(key);\n if (offlineValue !== null) {\n return offlineValue;\n }\n console.error(`[Togglely] Failed to fetch toggle \"${key}\":`, error);\n return null;\n }\n }\n getAllToggles() {\n const result = {};\n this.toggles.forEach((value, key) => {\n result[key] = value;\n });\n return result;\n }\n // ==================== Offline Fallback ====================\n /**\n * Load toggles from environment variables\n * Format: TOGGLELY_<TOGGLE_KEY>=<value> or TOGGLELY_<TOGGLE_KEY>_ENABLED=true\n */\n loadOfflineToggles() {\n try {\n // Browser environment - check window.__TOGGLELY_TOGGLES\n if (typeof window !== 'undefined' && window.__TOGGLELY_TOGGLES) {\n const offlineToggles = window.__TOGGLELY_TOGGLES;\n for (const [key, value] of Object.entries(offlineToggles)) {\n this.toggles.set(key, this.parseOfflineValue(value));\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from window.__TOGGLELY_TOGGLES');\n return;\n }\n // Node.js / Bun / Deno environment - check process.env\n if (typeof process !== 'undefined' && process.env) {\n const prefix = this.config.envPrefix;\n for (const [envKey, envValue] of Object.entries(process.env)) {\n if (envKey?.startsWith(prefix) && envValue !== undefined) {\n // Parse toggle key: TOGGLELY_MY_FEATURE -> my-feature\n const toggleKey = envKey\n .slice(prefix.length)\n .toLowerCase()\n .replace(/_/g, '-');\n this.toggles.set(toggleKey, this.parseOfflineValue(envValue));\n }\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from environment variables');\n }\n }\n catch (error) {\n console.warn('[Togglely] Failed to load offline toggles:', error);\n }\n }\n getOfflineToggle(key) {\n if (!this.config.offlineFallback)\n return null;\n // Try to get from already loaded offline toggles\n const cached = this.toggles.get(key);\n if (cached) {\n // If we haven't emitted offline event yet, do it now\n if (!this.state.isOffline) {\n this.state.isOffline = true;\n this.emit('offline');\n }\n return cached;\n }\n return null;\n }\n parseOfflineValue(value) {\n // Handle boolean strings\n if (typeof value === 'string') {\n const lower = value.toLowerCase();\n if (lower === 'true')\n return { value: true, enabled: true };\n if (lower === 'false')\n return { value: false, enabled: true };\n // Try to parse as number\n if (!isNaN(Number(value))) {\n return { value: Number(value), enabled: true };\n }\n // Try to parse as JSON\n try {\n const parsed = JSON.parse(value);\n return { value: parsed, enabled: true };\n }\n catch {\n // Return as string\n return { value, enabled: true };\n }\n }\n return { value, enabled: true };\n }\n // ==================== Refresh / Polling ====================\n async refresh() {\n try {\n const params = new URLSearchParams();\n if (this.config.apiKey)\n params.set('apiKey', this.config.apiKey);\n const brandKey = this.context.tenantId || this.context.brandKey;\n if (brandKey)\n params.set('brandKey', String(brandKey));\n // Always send context if available (needed for targeting rules)\n if (Object.keys(this.context).length > 0) {\n params.set('context', JSON.stringify(this.context));\n }\n const response = await this.fetchWithTimeout(`${this.config.baseUrl}/sdk/flags/${this.config.project}/${this.config.environment}?${params.toString()}`, {\n headers: {\n 'Authorization': `Bearer ${this.config.apiKey}`,\n 'Content-Type': 'application/json'\n }\n });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n const data = await response.json();\n this.toggles.clear();\n for (const [key, value] of Object.entries(data)) {\n this.toggles.set(key, value);\n }\n this.state.lastFetch = new Date();\n this.state.lastError = null;\n if (!this.state.isReady) {\n this.state.isReady = true;\n this.emit('ready');\n }\n // If we were offline, go online\n if (this.state.isOffline) {\n this.state.isOffline = false;\n this.emit('online');\n }\n this.emit('update');\n }\n catch (error) {\n this.state.lastError = error;\n // If we have offline toggles, switch to offline mode\n if (this.config.offlineFallback && this.offlineTogglesLoaded) {\n if (!this.state.isOffline) {\n this.state.isOffline = true;\n this.emit('offline');\n }\n }\n this.emit('error');\n console.error('[Togglely] Failed to refresh toggles:', error);\n }\n }\n forceOfflineMode() {\n this.state.isOffline = true;\n this.emit('offline');\n }\n forceOnlineMode() {\n this.state.isOffline = false;\n this.refresh();\n this.emit('online');\n }\n // ==================== Cleanup ====================\n destroy() {\n this.toggles.clear();\n this.eventHandlers.forEach(handlers => handlers.clear());\n }\n // ==================== Private Helpers ====================\n fetchWithTimeout(url, options) {\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n reject(new Error('Request timeout'));\n }, this.config.timeout);\n fetch(url, options)\n .then(response => {\n clearTimeout(timeoutId);\n resolve(response);\n })\n .catch(error => {\n clearTimeout(timeoutId);\n reject(error);\n });\n });\n }\n}\n// ==================== Utility Functions ====================\n/**\n * Create a client-side toggle loader script\n * Use this to inject offline toggles into your HTML\n */\nfunction createOfflineTogglesScript(toggles) {\n return `<script>window.__TOGGLELY_TOGGLES = ${JSON.stringify(toggles)};</script>`;\n}\n/**\n * Helper to convert toggles to environment variables\n */\nfunction togglesToEnvVars(toggles, prefix = 'TOGGLELY_') {\n const envVars = {};\n for (const [key, value] of Object.entries(toggles)) {\n const envKey = prefix + key.toUpperCase().replace(/-/g, '_');\n envVars[envKey] = typeof value === 'object' ? JSON.stringify(value) : String(value);\n }\n return envVars;\n}\n\nexport { TogglelyClient, createOfflineTogglesScript, TogglelyClient as default, togglesToEnvVars };\n//# sourceMappingURL=index.esm.js.map\n",null],"names":["TogglelyClient","constructor","config","this","toggles","Map","context","state","isReady","isOffline","lastError","lastFetch","eventHandlers","offlineTogglesLoaded","timeout","offlineFallback","envPrefix","autoFetch","set","Set","loadOfflineToggles","refresh","on","event","handler","handlers","get","add","off","delete","emit","forEach","setContext","getContext","clearContext","getState","isEnabled","key","defaultValue","value","getValue","enabled","getString","String","getNumber","Number","getJSON","JSON","parse","Object","keys","length","cached","params","URLSearchParams","brandKey","tenantId","stringify","query","toString","response","fetchWithTimeout","baseUrl","project","environment","headers","Authorization","apiKey","ok","status","Error","data","json","error","offlineValue","getOfflineToggle","console","getAllToggles","result","window","__TOGGLELY_TOGGLES","offlineToggles","entries","parseOfflineValue","log","process","env","prefix","envKey","envValue","startsWith","undefined","toggleKey","slice","toLowerCase","replace","warn","lower","isNaN","clear","Date","forceOfflineMode","forceOnlineMode","destroy","url","options","Promise","resolve","reject","timeoutId","setTimeout","fetch","then","clearTimeout","catch","getGlobalTogglely","togglely","async","client","updateAll","selectors","invert","Array","isArray","selector","isToggleEnabled","shouldShow","document","querySelectorAll","el","style","display","hideClass","showClass","classList","remove","envVars","toUpperCase"],"mappings":"8OAQA,MAAMA,EACF,WAAAC,CAAYC,GACRC,KAAKC,QAAU,IAAIC,IACnBF,KAAKG,QAAU,CAAA,EACfH,KAAKI,MAAQ,CACTC,SAAS,EACTC,WAAW,EACXC,UAAW,KACXC,UAAW,MAEfR,KAAKS,cAAgB,IAAIP,IACzBF,KAAKU,sBAAuB,EAC5BV,KAAKD,OAAS,CACVY,QAAS,IACTC,iBAAiB,EACjBC,UAAW,YACXC,WAAW,KACRf,GAGPC,KAAKS,cAAcM,IAAI,QAAS,IAAIC,KACpChB,KAAKS,cAAcM,IAAI,SAAU,IAAIC,KACrChB,KAAKS,cAAcM,IAAI,QAAS,IAAIC,KACpChB,KAAKS,cAAcM,IAAI,UAAW,IAAIC,KACtChB,KAAKS,cAAcM,IAAI,SAAU,IAAIC,KAEjChB,KAAKD,OAAOa,iBACZZ,KAAKiB,qBAGLjB,KAAKD,OAAOe,WACZd,KAAKkB,SAEb,CAEA,EAAAC,CAAGC,EAAOC,GACN,MAAMC,EAAWtB,KAAKS,cAAcc,IAAIH,GAIxC,OAHIE,GACAA,EAASE,IAAIH,GAEV,IAAMrB,KAAKyB,IAAIL,EAAOC,EAC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,EAAIoG,cAAc1C,QAAQ,KAAM,MACrB,iBAAVxD,EAAqBQ,KAAKU,UAAUlB,GAASI,OAAOJ,EACjF,CACA,OAAOiG,CACX"}
|
|
1
|
+
{"version":3,"file":"index.umd.min.js","sources":["../../core/dist/index.esm.js","../src/index.ts"],"sourcesContent":["/**\n * Togglely Core SDK - Framework agnostic feature flag management\n *\n * Features:\n * - Real-time feature flag evaluation\n * - Offline fallback via JSON file, environment variables, or window object\n * - Multi-brand/tenant support\n * - Type-safe flag access\n * - Build-time JSON generation for offline-first deployment\n */\n// ==================== Togglely Client ====================\nclass TogglelyClient {\n constructor(config) {\n this.toggles = new Map();\n this.context = {};\n this.state = {\n isReady: false,\n isOffline: false,\n lastError: null,\n lastFetch: null\n };\n this.eventHandlers = new Map();\n this.offlineTogglesLoaded = false;\n this.config = {\n timeout: 5000,\n offlineFallback: true,\n envPrefix: 'TOGGLELY_',\n autoFetch: true,\n offlineJsonPath: undefined,\n ...config\n };\n // Initialize event handlers\n this.eventHandlers.set('ready', new Set());\n this.eventHandlers.set('update', new Set());\n this.eventHandlers.set('error', new Set());\n this.eventHandlers.set('offline', new Set());\n this.eventHandlers.set('online', new Set());\n // Set initial context if provided (including brandKey/tenantId)\n const initialContext = { ...config.context };\n if (config.brandKey)\n initialContext.brandKey = config.brandKey;\n if (config.tenantId)\n initialContext.tenantId = config.tenantId;\n this.context = initialContext;\n // Load offline toggles first (if enabled)\n if (this.config.offlineFallback) {\n this.loadOfflineToggles();\n }\n // Initial fetch (if enabled)\n if (this.config.autoFetch) {\n this.refresh();\n }\n }\n // ==================== Event Handling ====================\n on(event, handler) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.add(handler);\n }\n return () => this.off(event, handler);\n }\n off(event, handler) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.delete(handler);\n }\n }\n emit(event) {\n const handlers = this.eventHandlers.get(event);\n if (handlers) {\n handlers.forEach(handler => handler({ ...this.state }));\n }\n }\n // ==================== Context ====================\n setContext(context) {\n this.context = { ...this.context, ...context };\n }\n getContext() {\n return { ...this.context };\n }\n clearContext() {\n this.context = {};\n }\n // ==================== State ====================\n getState() {\n return { ...this.state };\n }\n isReady() {\n return this.state.isReady;\n }\n isOffline() {\n return this.state.isOffline;\n }\n // ==================== Toggle Accessors ====================\n /**\n * Check if a boolean feature flag is enabled\n * @param key - The flag key\n * @param defaultValue - Default value if flag not found\n * @returns Promise<boolean>\n */\n async isEnabled(key, defaultValue = false) {\n const value = await this.getValue(key);\n if (value === null) {\n return defaultValue;\n }\n return value.enabled && value.value === true;\n }\n /**\n * Get a string feature flag value\n * @param key - The flag key\n * @param defaultValue - Default value if flag not found or disabled\n * @returns Promise<string>\n */\n async getString(key, defaultValue = '') {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n return String(value.value);\n }\n /**\n * Get a number feature flag value\n * @param key - The flag key\n * @param defaultValue - Default value if flag not found or disabled\n * @returns Promise<number>\n */\n async getNumber(key, defaultValue = 0) {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n return Number(value.value);\n }\n /**\n * Get a JSON feature flag value\n * @param key - The flag key\n * @param defaultValue - Default value if flag not found or disabled\n * @returns Promise<T>\n */\n async getJSON(key, defaultValue = {}) {\n const value = await this.getValue(key);\n if (value === null || !value.enabled)\n return defaultValue;\n if (typeof value.value === 'string') {\n try {\n return JSON.parse(value.value);\n }\n catch {\n return defaultValue;\n }\n }\n return value.value;\n }\n /**\n * Get raw toggle value\n * @param key - The flag key\n * @returns Promise<ToggleValue | null>\n */\n async getValue(key) {\n // Try cache first - but only if no context is set\n if (Object.keys(this.context).length === 0) {\n const cached = this.toggles.get(key);\n if (cached) {\n return cached;\n }\n }\n // Fetch from server\n try {\n const params = new URLSearchParams();\n if (this.config.apiKey)\n params.set('apiKey', this.config.apiKey);\n const brandKey = this.context.tenantId || this.context.brandKey;\n if (brandKey)\n params.set('tenantId', String(brandKey));\n if (Object.keys(this.context).length > 0) {\n params.set('context', JSON.stringify(this.context));\n }\n const query = params.toString() ? `?${params.toString()}` : '';\n const url = `${this.config.baseUrl}/sdk/flags/${encodeURIComponent(this.config.project)}/${encodeURIComponent(this.config.environment)}/${encodeURIComponent(key)}${query}`;\n const response = await this.fetchWithTimeout(url, { headers: { 'Content-Type': 'application/json' } });\n if (!response.ok) {\n if (response.status === 404) {\n return null;\n }\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n const data = await response.json();\n this.toggles.set(key, data);\n if (this.state.isOffline) {\n this.state.isOffline = false;\n this.emit('online');\n }\n return data;\n }\n catch (error) {\n // Try offline fallback\n if (this.config.offlineFallback) {\n const offlineValue = this.getOfflineToggle(key);\n if (offlineValue !== null) {\n return offlineValue;\n }\n }\n // Return safe default\n return { value: false, enabled: false };\n }\n }\n /**\n * Get all toggles\n * @returns Record<string, ToggleValue>\n */\n getAllToggles() {\n const result = {};\n this.toggles.forEach((value, key) => {\n result[key] = value;\n });\n return result;\n }\n // ==================== Offline Fallback ====================\n /**\n * Load offline toggles from multiple sources (in priority order):\n * 1. Inline offlineToggles from config\n * 2. JSON file (if offlineJsonPath is set)\n * 3. window.__TOGGLELY_TOGGLES (browser)\n * 4. Environment variables (Node.js)\n */\n loadOfflineToggles() {\n try {\n // Priority 1: Inline offline toggles from config\n if (this.config.offlineToggles && Object.keys(this.config.offlineToggles).length > 0) {\n for (const [key, value] of Object.entries(this.config.offlineToggles)) {\n this.toggles.set(key, value);\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from config');\n return;\n }\n // Priority 2: JSON file (browser only - fetch synchronously not possible, will try async)\n if (this.config.offlineJsonPath && typeof window !== 'undefined') {\n this.loadOfflineJsonFile(this.config.offlineJsonPath);\n }\n // Priority 3: Browser environment - check window.__TOGGLELY_TOGGLES\n if (typeof window !== 'undefined' && window.__TOGGLELY_TOGGLES) {\n const offlineToggles = window.__TOGGLELY_TOGGLES;\n for (const [key, value] of Object.entries(offlineToggles)) {\n this.toggles.set(key, this.parseOfflineValue(value));\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from window.__TOGGLELY_TOGGLES');\n return;\n }\n // Priority 4: Node.js / Bun / Deno environment - check process.env\n if (typeof process !== 'undefined' && process.env) {\n const prefix = this.config.envPrefix;\n for (const [envKey, envValue] of Object.entries(process.env)) {\n if (envKey?.startsWith(prefix) && envValue !== undefined) {\n const toggleKey = envKey\n .slice(prefix.length)\n .toLowerCase()\n .replace(/_/g, '-');\n this.toggles.set(toggleKey, this.parseOfflineValue(envValue));\n }\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from environment variables');\n }\n }\n catch (error) {\n console.warn('[Togglely] Failed to load offline toggles:', error);\n }\n }\n /**\n * Load offline toggles from JSON file (async)\n */\n async loadOfflineJsonFile(path) {\n try {\n if (typeof window !== 'undefined') {\n // Browser - fetch the JSON file\n const response = await fetch(path);\n if (response.ok) {\n const data = await response.json();\n for (const [key, value] of Object.entries(data)) {\n this.toggles.set(key, this.parseOfflineValue(value));\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from JSON file:', path);\n }\n }\n else if (typeof require !== 'undefined') {\n // Node.js - require the JSON file\n const fs = require('fs');\n const pathModule = require('path');\n const fullPath = pathModule.resolve(path);\n if (fs.existsSync(fullPath)) {\n const data = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));\n for (const [key, value] of Object.entries(data)) {\n this.toggles.set(key, this.parseOfflineValue(value));\n }\n this.offlineTogglesLoaded = true;\n console.log('[Togglely] Loaded offline toggles from JSON file:', fullPath);\n }\n }\n }\n catch (error) {\n console.warn('[Togglely] Failed to load offline JSON file:', error);\n }\n }\n getOfflineToggle(key) {\n if (!this.config.offlineFallback)\n return null;\n const cached = this.toggles.get(key);\n if (cached) {\n if (!this.state.isOffline) {\n this.state.isOffline = true;\n this.emit('offline');\n }\n return cached;\n }\n return null;\n }\n parseOfflineValue(value) {\n if (typeof value === 'string') {\n const lower = value.toLowerCase();\n if (lower === 'true')\n return { value: true, enabled: true };\n if (lower === 'false')\n return { value: false, enabled: true };\n if (!isNaN(Number(value))) {\n return { value: Number(value), enabled: true };\n }\n try {\n const parsed = JSON.parse(value);\n return { value: parsed, enabled: true };\n }\n catch {\n return { value, enabled: true };\n }\n }\n return { value, enabled: true };\n }\n // ==================== Refresh / Polling ====================\n /**\n * Refresh all toggles from the server\n */\n async refresh() {\n try {\n const params = new URLSearchParams();\n if (this.config.apiKey)\n params.set('apiKey', this.config.apiKey);\n const brandKey = this.context.tenantId || this.context.brandKey;\n if (brandKey)\n params.set('tenantId', String(brandKey));\n if (Object.keys(this.context).length > 0) {\n params.set('context', JSON.stringify(this.context));\n }\n const response = await this.fetchWithTimeout(`${this.config.baseUrl}/sdk/flags/${encodeURIComponent(this.config.project)}/${encodeURIComponent(this.config.environment)}?${params.toString()}`, { headers: { 'Content-Type': 'application/json' } });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n const data = await response.json();\n this.toggles.clear();\n for (const [key, value] of Object.entries(data)) {\n this.toggles.set(key, value);\n }\n this.state.lastFetch = new Date();\n this.state.lastError = null;\n if (!this.state.isReady) {\n this.state.isReady = true;\n this.emit('ready');\n }\n if (this.state.isOffline) {\n this.state.isOffline = false;\n this.emit('online');\n }\n this.emit('update');\n }\n catch (error) {\n this.state.lastError = error;\n if (this.config.offlineFallback && this.offlineTogglesLoaded) {\n if (!this.state.isOffline) {\n this.state.isOffline = true;\n this.emit('offline');\n }\n }\n this.emit('error');\n console.error('[Togglely] Failed to refresh toggles:', error);\n }\n }\n forceOfflineMode() {\n this.state.isOffline = true;\n this.emit('offline');\n }\n forceOnlineMode() {\n this.state.isOffline = false;\n this.refresh();\n this.emit('online');\n }\n // ==================== Cleanup ====================\n destroy() {\n this.toggles.clear();\n this.eventHandlers.forEach(handlers => handlers.clear());\n }\n // ==================== Private Helpers ====================\n fetchWithTimeout(url, options) {\n return new Promise((resolve, reject) => {\n const timeoutId = setTimeout(() => {\n reject(new Error('Request timeout'));\n }, this.config.timeout);\n fetch(url, options)\n .then(response => {\n clearTimeout(timeoutId);\n resolve(response);\n })\n .catch(error => {\n clearTimeout(timeoutId);\n reject(error);\n });\n });\n }\n}\n// ==================== Utility Functions ====================\n/**\n * Create a client-side toggle loader script\n * Use this to inject offline toggles into your HTML\n */\nfunction createOfflineTogglesScript(toggles) {\n return `<script>window.__TOGGLELY_TOGGLES = ${JSON.stringify(toggles)};</script>`;\n}\n/**\n * Helper to convert toggles to environment variables\n */\nfunction togglesToEnvVars(toggles, prefix = 'TOGGLELY_') {\n const envVars = {};\n for (const [key, value] of Object.entries(toggles)) {\n const envKey = prefix + key.toUpperCase().replace(/-/g, '_');\n envVars[envKey] = typeof value === 'object' ? JSON.stringify(value) : String(value);\n }\n return envVars;\n}\n\nexport { TogglelyClient, createOfflineTogglesScript, TogglelyClient as default, togglesToEnvVars };\n//# sourceMappingURL=index.esm.js.map\n",null],"names":["TogglelyClient","constructor","config","this","toggles","Map","context","state","isReady","isOffline","lastError","lastFetch","eventHandlers","offlineTogglesLoaded","timeout","offlineFallback","envPrefix","autoFetch","offlineJsonPath","undefined","set","Set","initialContext","brandKey","tenantId","loadOfflineToggles","refresh","on","event","handler","handlers","get","add","off","delete","emit","forEach","setContext","getContext","clearContext","getState","isEnabled","key","defaultValue","value","getValue","enabled","getString","String","getNumber","Number","getJSON","JSON","parse","Object","keys","length","cached","params","URLSearchParams","apiKey","stringify","query","toString","url","baseUrl","encodeURIComponent","project","environment","response","fetchWithTimeout","headers","ok","status","Error","statusText","data","json","error","offlineValue","getOfflineToggle","getAllToggles","result","offlineToggles","entries","console","log","window","loadOfflineJsonFile","__TOGGLELY_TOGGLES","parseOfflineValue","process","env","prefix","envKey","envValue","startsWith","toggleKey","slice","toLowerCase","replace","warn","path","fetch","require","fs","fullPath","resolve","existsSync","readFileSync","lower","isNaN","clear","Date","forceOfflineMode","forceOnlineMode","destroy","options","Promise","reject","timeoutId","setTimeout","then","clearTimeout","catch","getGlobalTogglely","togglely","async","client","updateAll","selectors","invert","Array","isArray","selector","isToggleEnabled","shouldShow","document","querySelectorAll","el","style","display","hideClass","showClass","classList","remove","envVars","toUpperCase"],"mappings":"8OAWA,MAAMA,EACF,WAAAC,CAAYC,GACRC,KAAKC,QAAU,IAAIC,IACnBF,KAAKG,QAAU,CAAA,EACfH,KAAKI,MAAQ,CACTC,SAAS,EACTC,WAAW,EACXC,UAAW,KACXC,UAAW,MAEfR,KAAKS,cAAgB,IAAIP,IACzBF,KAAKU,sBAAuB,EAC5BV,KAAKD,OAAS,CACVY,QAAS,IACTC,iBAAiB,EACjBC,UAAW,YACXC,WAAW,EACXC,qBAAiBC,KACdjB,GAGPC,KAAKS,cAAcQ,IAAI,QAAS,IAAIC,KACpClB,KAAKS,cAAcQ,IAAI,SAAU,IAAIC,KACrClB,KAAKS,cAAcQ,IAAI,QAAS,IAAIC,KACpClB,KAAKS,cAAcQ,IAAI,UAAW,IAAIC,KACtClB,KAAKS,cAAcQ,IAAI,SAAU,IAAIC,KAErC,MAAMC,EAAiB,IAAKpB,EAAOI,SAC/BJ,EAAOqB,WACPD,EAAeC,SAAWrB,EAAOqB,UACjCrB,EAAOsB,WACPF,EAAeE,SAAWtB,EAAOsB,UACrCrB,KAAKG,QAAUgB,EAEXnB,KAAKD,OAAOa,iBACZZ,KAAKsB,qBAGLtB,KAAKD,OAAOe,WACZd,KAAKuB,SAEb,CAEA,EAAAC,CAAGC,EAAOC,GACN,MAAMC,EAAW3B,KAAKS,cAAcmB,IAAIH,GAIxC,OAHIE,GACAA,EAASE,IAAIH,GAEV,IAAM1B,KAAK8B,IAAIL,EAAOC,EACjC,CACA,GAAAI,CAAIL,EAAOC,GACP,MAAMC,EAAW3B,KAAKS,cAAcmB,IAAIH,GACpCE,GACAA,EAASI,OAAOL,EAExB,CACA,IAAAM,CAAKP,GACD,MAAME,EAAW3B,KAAKS,cAAcmB,IAAIH,GAC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
1
|
-
{
|
|
2
|
-
"name": "@togglely/sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Vanilla JavaScript SDK for Togglely - Feature toggles for any framework",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.esm.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"unpkg": "dist/index.umd.js",
|
|
9
|
-
"files": [
|
|
10
|
-
"dist"
|
|
11
|
-
],
|
|
12
|
-
"scripts": {
|
|
13
|
-
"build": "tsc && rollup -c",
|
|
14
|
-
"test": "jest"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"feature-flags",
|
|
18
|
-
"feature-toggles",
|
|
19
|
-
"togglely",
|
|
20
|
-
"vanilla",
|
|
21
|
-
"javascript"
|
|
22
|
-
],
|
|
23
|
-
"author": "Togglely",
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@togglely/sdk-core": "^1.0.0"
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
30
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
31
|
-
"@rollup/plugin-typescript": "^11.1.5",
|
|
32
|
-
"rollup": "^4.9.1",
|
|
33
|
-
"tslib": "^2.6.2",
|
|
34
|
-
"typescript": "^5.3.3"
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@togglely/sdk",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Vanilla JavaScript SDK for Togglely - Feature toggles for any framework",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"unpkg": "dist/index.umd.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc && rollup -c",
|
|
14
|
+
"test": "jest"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"feature-flags",
|
|
18
|
+
"feature-toggles",
|
|
19
|
+
"togglely",
|
|
20
|
+
"vanilla",
|
|
21
|
+
"javascript"
|
|
22
|
+
],
|
|
23
|
+
"author": "Togglely",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@togglely/sdk-core": "^1.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
30
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
31
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
32
|
+
"rollup": "^4.9.1",
|
|
33
|
+
"tslib": "^2.6.2",
|
|
34
|
+
"typescript": "^5.3.3"
|
|
35
|
+
}
|
|
36
36
|
}
|