Skip to content

Commit 54b7c34

Browse files
committed
chore: updated setup guide ad readme for correctness
1 parent d895795 commit 54b7c34

9 files changed

Lines changed: 131 additions & 60 deletions

File tree

.github/CONTRIBUTING.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,52 @@ RESEND_API_KEY=<YOUR_RESEND_API_KEY>
201201
TINYBIRD_TOKEN=<YOUR_TINYBIRD_TOKEN>
202202
```
203203

204+
## Local Development with SDKs
205+
206+
When testing the SDKs locally with a local API server running on `localhost:5000`, you'll need to configure the `__internal_baseUrl` option to point to your local development server instead of the production API.
207+
208+
### Using SDKs Locally
209+
210+
For **JavaScript SDK**:
211+
212+
```javascript
213+
import { Flagix } from "@flagix/js-sdk";
214+
215+
await Flagix.initialize({
216+
apiKey: "your-dev-api-key",
217+
__internal_baseUrl: "http://localhost:5000", // Points to local API server
218+
initialContext: {
219+
userId: "test_user",
220+
email: "test@example.com"
221+
}
222+
});
223+
```
224+
225+
For **React SDK**:
226+
227+
```jsx
228+
import { FlagixProvider } from "@flagix/react";
229+
230+
const options = {
231+
apiKey: "your-dev-api-key",
232+
__internal_baseUrl: "http://localhost:5000", // Points to local API server
233+
initialContext: {
234+
userId: "test_user",
235+
email: "test@example.com"
236+
}
237+
};
238+
239+
function App() {
240+
return (
241+
<FlagixProvider options={options}>
242+
<YourApp />
243+
</FlagixProvider>
244+
);
245+
}
246+
```
247+
248+
**Note:** The `__internal_baseUrl` option is for local development and testing only. Do not include it in production code—the SDK will automatically use the production API endpoint.
249+
204250
## Running the Apps
205251

206252
From the root you can run all apps:

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import { Flagix } from "@flagix/js-sdk";
5555
// Initialize the SDK.
5656
await Flagix.initialize({
5757
apiKey: "<YOUR_API_KEY>",
58-
apiBaseUrl: "https://api.flagix.com",
5958
});
6059

6160
// Set user context (triggers instant re-evaluation)
@@ -82,7 +81,6 @@ import { useAuth } from "./hooks/use-auth";
8281

8382
const options = {
8483
apiKey: "<YOUR_API_KEY>",
85-
apiBaseUrl: "https://api.flagix.com",
8684
};
8785

8886
export default function Providers({ children }: { children: React.ReactNode }) {

apps/docs/content/docs/environments.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ const env = process.env.NODE_ENV; // "development", "staging", "production"
8080
// Initialize Flagix with environment-specific API key
8181
await Flagix.initialize({
8282
apiKey: process.env[`FLAGIX_API_KEY_${env.toUpperCase()}`],
83-
apiBaseUrl: process.env.FLAGIX_API_URL,
8483
initialContext: {
8584
userId: user.id,
8685
environment: env

apps/docs/content/docs/index.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { Flagix } from "@flagix/js-sdk";
3434

3535
await Flagix.initialize({
3636
apiKey: "your-api-key",
37-
apiBaseUrl: "https://api.flagix.com",
3837
initialContext: {
3938
userId: "user_123",
4039
email: "user@example.com",
@@ -67,7 +66,6 @@ import { FlagixProvider } from "@flagix/react";
6766
function App() {
6867
const options = {
6968
apiKey: "your-api-key",
70-
apiBaseUrl: "https://api.flagix.com",
7169
initialContext: { userId: "user_123" }
7270
}
7371

apps/docs/content/docs/installation.mdx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import { Flagix } from "@flagix/js-sdk";
5454
// Initialize the SDK
5555
await Flagix.initialize({
5656
apiKey: "your-api-key-here",
57-
apiBaseUrl: "https://api.flagix.com",
5857
initialContext: {
5958
userId: "user_123",
6059
email: "user@example.com",
@@ -71,17 +70,14 @@ Wrap your application with the `FlagixProvider` (see the [React & Next.js SDK re
7170
**Simple React example:**
7271
```jsx
7372
import { FlagixProvider } from "@flagix/react";
74-
7573
const options = {
7674
apiKey: "your-api-key-here",
77-
apiBaseUrl: "https://api.flagix.com",
7875
initialContext: {
7976
userId: "user_123",
8077
email: "user@example.com",
8178
plan: "premium"
8279
},
8380
};
84-
8581
function App() {
8682
return (
8783
<FlagixProvider options={options}>
@@ -98,7 +94,6 @@ import { useAuth } from "./hooks/use-auth"; // Your auth hook
9894

9995
const options = {
10096
apiKey: "your-api-key-here",
101-
apiBaseUrl: "https://api.flagix.com",
10297
};
10398

10499
function App() {
@@ -123,7 +118,6 @@ For **Next.js App Router**, create a `providers.tsx` file and wrap your root lay
123118
| Option | Type | Required | Description |
124119
|--------|------|----------|-------------|
125120
| `apiKey` | `string` || Your Flagix API key |
126-
| `apiBaseUrl` | `string` || Base URL for the Flagix API |
127121
| `initialContext` | `object` || Initial evaluation context |
128122
| `context` (React only) | `object` || Dynamic context that syncs automatically |
129123
| `logs.level` | `string` || Set to `info`, `warn`, or `error` to see internal SDK logs in the console. |
@@ -137,15 +131,13 @@ Store your API credentials in environment variables:
137131
```bash
138132
# .env
139133
FLAGIX_API_KEY=your-api-key
140-
FLAGIX_API_URL=https://api.flagix.com
141134
```
142135

143136
Then in your code:
144137

145138
```javascript
146139
await Flagix.initialize({
147140
apiKey: process.env.FLAGIX_API_KEY,
148-
apiBaseUrl: process.env.FLAGIX_API_URL,
149141
initialContext: { userId: "user_123" }
150142
});
151143
```
@@ -157,15 +149,13 @@ Environment variables must be prefixed with `NEXT_PUBLIC_` to be accessible in t
157149
```bash
158150
# .env
159151
NEXT_PUBLIC_FLAGIX_API_KEY=your-api-key
160-
NEXT_PUBLIC_FLAGIX_API_URL=https://api.flagix.com
161152
```
162153

163154
Then use them in your provider component:
164155

165156
```jsx
166157
const options = {
167158
apiKey: process.env.NEXT_PUBLIC_FLAGIX_API_KEY,
168-
apiBaseUrl: process.env.NEXT_PUBLIC_FLAGIX_API_URL,
169159
};
170160
```
171161

apps/docs/content/docs/sdk/javascript.mdx

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ async initialize(options: FlagixClientOptions): Promise<void>
2424
```typescript
2525
interface FlagixClientOptions {
2626
apiKey: string; // Required: Your API key
27-
apiBaseUrl: string; // Required: base URL
2827
initialContext?: EvaluationContext; // Optional: Initial context
2928
logs?: {
3029
level?: "none" | "error" | "warn" | "info"; // Optional: default "none"
@@ -39,7 +38,6 @@ import { Flagix } from "@flagix/js-sdk";
3938

4039
await Flagix.initialize({
4140
apiKey: "your-api-key",
42-
apiBaseUrl: "https://api.flagix.com",
4341
initialContext: {
4442
userId: "user_123",
4543
email: "user@example.com",
@@ -161,6 +159,57 @@ Flagix.setContext({
161159
// → Reactive updates triggered again
162160
```
163161

162+
### Flagix.identify()
163+
164+
Replaces the entire global evaluation context, clearing all previous context values.
165+
166+
```typescript
167+
identify(newContext: EvaluationContext): void
168+
```
169+
170+
#### Parameters
171+
172+
- `newContext` - New context object that will completely replace the existing context
173+
174+
#### Use Cases
175+
176+
Unlike `setContext()` which merges with existing context, `identify()` is useful when you need to:
177+
178+
- **Clear user context on logout**: Remove all user-specific attributes
179+
- **Switch between different users**: Replace one user's context entirely with another's
180+
- **Reset evaluation context**: Start fresh with a completely new context
181+
182+
#### Reactivity
183+
184+
Calling `identify()` instantly replaces the global context and triggers re-evaluation of all cached flags. Any active listeners subscribed via `onFlagUpdate()` are triggered.
185+
186+
#### Examples
187+
188+
```javascript
189+
// On user logout - completely clear context
190+
Flagix.identify({});
191+
// → All previous context is removed
192+
// → All flags re-evaluate with empty context
193+
// → All onFlagUpdate listeners are triggered
194+
195+
// Switch to a different user
196+
Flagix.identify({
197+
userId: "new_user_456",
198+
email: "newuser@example.com",
199+
plan: "basic"
200+
});
201+
// → Previous context is completely replaced
202+
// → No old user data persists
203+
// → Flags re-evaluate with new user context
204+
205+
// Distinguish between setContext and identify
206+
// Use setContext for incremental updates
207+
Flagix.setContext({ lastActivity: new Date() });
208+
209+
// Use identify for complete context replacement
210+
Flagix.identify({ userId: "user_new", role: "admin" });
211+
```
212+
164213
### Flagix.onFlagUpdate()
165214

166215
Subscribes to real-time flag updates triggered by `setContext()` or server-sent events.

apps/docs/content/docs/sdk/react.mdx

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { FlagixProvider } from "@flagix/react";
2424

2525
const options = {
2626
apiKey: "your-api-key",
27-
apiBaseUrl: "https://api.flagix.com",
2827
initialContext: {
2928
userId: "user_123",
3029
email: "user@example.com",
@@ -59,7 +58,6 @@ import type React from "react";
5958

6059
const flagixOptions = {
6160
apiKey: "your-api-key",
62-
apiBaseUrl: "https://api.flagix.com",
6361
initialContext: {
6462
userId: "user_123",
6563
email: "user@example.com",
@@ -111,7 +109,6 @@ import { FlagixProvider } from "@flagix/react";
111109

112110
const flagixOptions = {
113111
apiKey: "your-api-key",
114-
apiBaseUrl: "https://api.flagix.com",
115112
initialContext: {
116113
userId: "user_123",
117114
email: "user@example.com",
@@ -157,7 +154,6 @@ import { FlagixProvider } from "@flagix/react";
157154

158155
const options = {
159156
apiKey: "your-api-key",
160-
apiBaseUrl: "https://api.flagix.com",
161157
initialContext: {
162158
userId: "user_123",
163159
email: "user@example.com",
@@ -186,7 +182,6 @@ import { useAuth } from "./hooks/use-auth"; // Your auth hook
186182

187183
const options = {
188184
apiKey: "your-api-key",
189-
apiBaseUrl: "https://api.flagix.com",
190185
};
191186

192187
function App() {
@@ -262,52 +257,50 @@ Hook for accessing Flagix actions like tracking events and updating context.
262257
function useFlagixActions(): {
263258
track: (eventName: string, properties?: Record<string, unknown>) => void;
264259
setContext: (newContext: EvaluationContext) => void;
260+
identify: (context?: EvaluationContext) => void;
265261
}
266262
```
267263

268-
#### When to Use `setContext()`
264+
#### track()
269265

270-
While the `context` prop on `FlagixProvider` is the recommended way to manage global user state, `setContext()` is still available for:
266+
Records custom events for analytics and conversion tracking.
271267

272-
- **Temporary overrides**: Quick testing or short-lived changes that don't warrant provider state updates
273-
- **Manual updates**: Fine-grained control in edge cases
274-
- **Vanilla JavaScript**: Applications not using a provider pattern
268+
```jsx
269+
const { track } = useFlagixActions();
275270
276-
For most authenticated applications, prefer passing user state via the `context` prop for cleaner, more declarative code.
271+
track("purchase_completed", {
272+
amount: 99.99,
273+
currency: "USD",
274+
productId: "prod_123"
275+
});
276+
```
277277

278-
#### Examples
278+
See [Flagix.track()](/docs/sdk/javascript#flagixtrack) in the JavaScript SDK for details.
279+
280+
#### setContext()
281+
282+
Merges new attributes with existing context. Use for incremental updates.
279283

280284
```jsx
281-
import { useFlagixActions } from "@flagix/react";
285+
const { setContext } = useFlagixActions();
282286
283-
function PurchaseButton() {
284-
const { track } = useFlagixActions();
285-
286-
const handlePurchase = () => {
287-
// Track purchase event
288-
track("purchase_completed", {
289-
amount: 99.99,
290-
currency: "USD",
291-
productId: "prod_123"
292-
});
293-
294-
// Process purchase...
295-
};
296-
297-
return <button onClick={handlePurchase}>Buy Now</button>;
298-
}
287+
setContext({ plan: "premium" }); // Adds/updates plan, keeps other context
288+
```
299289

300-
function TestComponent() {
301-
const { setContext } = useFlagixActions();
302-
303-
// Temporary context override for testing
304-
const handleTestAsAdmin = () => {
305-
setContext({ role: "admin" });
306-
};
307-
308-
return <button onClick={handleTestAsAdmin}>Test Admin Features</button>;
309-
}
290+
See [Flagix.setContext()](/docs/sdk/javascript#flagixsetcontext) in the JavaScript SDK for details.
291+
292+
#### identify()
293+
294+
Replaces entire context. Use for logout or switching users.
295+
296+
```jsx
297+
const { identify } = useFlagixActions();
298+
299+
identify({}); // Logout - clears all context
300+
identify({ userId: "new_user", plan: "free" }); // Switch user
310301
```
311-
---
302+
303+
See [Flagix.identify()](/docs/sdk/javascript#flagixidentify) in the JavaScript SDK for details.
304+
312305

313306
Need help? [contact support](https://x.com/flagixx).

apps/web/components/environment/setup-snippets.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { useAuth } from "./hooks/use-auth"; // Your auth hook
99
1010
const options = {
1111
apiKey: "${apiKey}",
12-
apiBaseUrl: "https://api.flagix.com",
1312
};
1413
1514
export default function Providers({ children }: { children: React.ReactNode }) {
@@ -45,7 +44,6 @@ export default function MyComponent() {
4544
// Initialize the SDK.
4645
await Flagix.initialize({
4746
apiKey: "${apiKey}",
48-
apiBaseUrl: "https://api.flagix.com",
4947
});
5048
5149
// Set user identity (triggers instant re-evaluation)

apps/web/components/home/hero.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const HeroSection = () => (
2222
<div className="group inline-flex items-center space-x-2 rounded-full border border-gray-300/50 bg-white/50 px-3 py-1 backdrop-blur-sm transition-all hover:border-gray-400">
2323
<span className="flex h-2 w-2 animate-pulse rounded-full bg-green-500" />
2424
<span className="font-medium text-gray-600 text-xs uppercase tracking-tight">
25-
v1.2.0 is live
25+
v1.0 is live
2626
</span>
2727
<div className="h-3 w-px bg-gray-300" />
2828
<Link

0 commit comments

Comments
 (0)