@productcraft/flags-react 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ProductCraft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,123 @@
1
- # Temporary Holding Version
1
+ # @productcraft/flags-react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React bindings for [ProductCraft Flags](https://productcraft.co/docs/flags): a provider, hooks, and server-side rendering without a flash of default values. It wraps [`FlagsClient`](https://github.com/clauderanelagh/productcraft-node/tree/main/packages/flags#readme), which downloads one config per environment and evaluates flags **locally**: user attributes never leave the app.
4
+
5
+ ```sh
6
+ npm install @productcraft/flags @productcraft/flags-react
7
+ ```
8
+
9
+ Peers: `react` 18 or later, `@productcraft/flags`. Works in Vite, Next.js (App and Pages Router), Remix and React Native.
10
+
11
+ > **A key used in a browser or mobile app makes its whole config public.** Anyone can read every flag key, segment key and cleartext rule value of that config. Put client-side flags in their own config with no internal rules, and keep server configs' keys on the server.
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { FlagsProvider, useFlag, useFlagDetails } from "@productcraft/flags-react";
17
+
18
+ export function App({ user }: { user: { id: string; plan: string } }) {
19
+ return (
20
+ <FlagsProvider options={{ sdkKey: import.meta.env.VITE_FLAGS_SDK_KEY }} user={{ identifier: user.id, custom: { plan: user.plan } }}>
21
+ <Checkout />
22
+ </FlagsProvider>
23
+ );
24
+ }
25
+
26
+ function Checkout() {
27
+ const newCheckout = useFlag("new_checkout", false); // boolean, from the default's type
28
+ const limits = useFlag("limits", { max: 5 }); // a json setting, parsed
29
+ const banner = useFlagDetails("banner_text", "Welcome"); // value + reason, rule, revision
30
+ return newCheckout ? <NewCheckout max={limits.max} banner={banner.value} /> : <OldCheckout />;
31
+ }
32
+ ```
33
+
34
+ | Export | What it does |
35
+ |---|---|
36
+ | `<FlagsProvider>` | `options` (any `FlagsClientOptions`: polling, `cache`, overrides …) builds a `FlagsClient` on mount and closes it on unmount; or pass `client` for one you own. Optional `bootstrap` (a config JSON) and `user` (the default user for the hooks). |
37
+ | `useFlag(key, default, user?)` | The value, typed after the default. The default until a config is there, or on any failure; never throws. |
38
+ | `useFlagDetails(key, default, user?)` | The value plus `reason`, `ruleIndex`, `percentageIndex`, `errorCode` and `revision`. |
39
+ | `useFlagsClient()` | The provider's `FlagsClient` (`getAllValues`, `forceRefresh`, events). |
40
+ | `useFlagsReady()` | `false` until the client's start-up settled (first download, or `maxInitWaitSeconds`). Always `false` on the server. |
41
+
42
+ Hooks evaluate synchronously against the client's current config and re-render (through `useSyncExternalStore`) only when the config or the client's state changes. A hook's own `user` replaces the provider's `user` as a whole. In the browser, auto polling pauses while the tab is hidden.
43
+
44
+ ## Server-side rendering (no flash, no hydration mismatch)
45
+
46
+ Evaluate on the server with a `FlagsClient` that holds the **same config** as the browser key (the client config), and pass its `snapshot().toJSON()` as `bootstrap`. The server render and the browser's first render (hydration) both evaluate that bootstrap, so they agree; the browser's own download starts after mount and re-renders if anything changed since.
47
+
48
+ ### Next.js App Router
49
+
50
+ ```tsx
51
+ // lib/flags.ts: one client per server process (the client config's key)
52
+ import { FlagsClient } from "@productcraft/flags";
53
+ export const serverFlags = new FlagsClient({ sdkKey: process.env.NEXT_PUBLIC_FLAGS_SDK_KEY! });
54
+
55
+ // app/layout.tsx (a server component)
56
+ import { FlagsProvider } from "@productcraft/flags-react";
57
+ import { serverFlags } from "@/lib/flags";
58
+ import { currentUser } from "@/lib/auth";
59
+
60
+ export default async function RootLayout({ children }: { children: React.ReactNode }) {
61
+ await serverFlags.waitForReady();
62
+ const user = await currentUser();
63
+ return (
64
+ <html lang="en">
65
+ <body>
66
+ <FlagsProvider
67
+ options={{ sdkKey: process.env.NEXT_PUBLIC_FLAGS_SDK_KEY! }}
68
+ bootstrap={serverFlags.snapshot().toJSON()}
69
+ user={{ identifier: user.id }}
70
+ >
71
+ {children}
72
+ </FlagsProvider>
73
+ </body>
74
+ </html>
75
+ );
76
+ }
77
+ ```
78
+
79
+ `@productcraft/flags-react` is marked `"use client"`, so a server component can render `<FlagsProvider>` directly; pass `options` (plain data), not a `client`, across that boundary. Server components that only need a value call `serverFlags.snapshot().getValue(key, default, user)` themselves. On the server the provider never downloads.
80
+
81
+ ### Next.js Pages Router
82
+
83
+ Return the bootstrap from `getServerSideProps` (or `getStaticProps` with `revalidate`), and wrap the page in `_app.tsx`:
84
+
85
+ ```tsx
86
+ // pages/_app.tsx
87
+ import type { AppProps } from "next/app";
88
+ import { FlagsProvider } from "@productcraft/flags-react";
89
+
90
+ export default function MyApp({ Component, pageProps }: AppProps) {
91
+ return (
92
+ <FlagsProvider options={{ sdkKey: process.env.NEXT_PUBLIC_FLAGS_SDK_KEY! }} bootstrap={pageProps.flagsBootstrap} user={pageProps.flagsUser}>
93
+ <Component {...pageProps} />
94
+ </FlagsProvider>
95
+ );
96
+ }
97
+
98
+ // in a page: getServerSideProps returns { props: { flagsBootstrap: serverFlags.snapshot().toJSON(), flagsUser: { identifier: user.id } } }
99
+ ```
100
+
101
+ The bootstrap is the config JSON the browser would download anyway (plus any overrides the server client has, so do not set server-only overrides on that client).
102
+
103
+ ## Testing
104
+
105
+ Pass a test client from `@productcraft/flags/testing`:
106
+
107
+ ```tsx
108
+ import { render, screen, act } from "@testing-library/react";
109
+ import { createTestClient } from "@productcraft/flags/testing";
110
+ import { FlagsProvider } from "@productcraft/flags-react";
111
+
112
+ const flags = createTestClient({ values: { new_checkout: true } });
113
+ render(<FlagsProvider client={flags}><Checkout /></FlagsProvider>);
114
+ act(() => flags.set("new_checkout", false)); // re-renders
115
+ ```
116
+
117
+ ## React Native
118
+
119
+ The `react-native` export condition of `@productcraft/flags` gives Metro the same build as browsers (no `node:` modules). There is no page visibility there, so auto polling keeps its interval; call `useFlagsClient().forceRefresh()` from an `AppState` listener if you want a refresh on foreground. For a persistent cache pass `options.cache` over AsyncStorage (`get` and `set` may return promises).
120
+
121
+ ## License
122
+
123
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,123 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ FlagsProvider: () => FlagsProvider,
25
+ useFlag: () => useFlag,
26
+ useFlagDetails: () => useFlagDetails,
27
+ useFlagsClient: () => useFlagsClient,
28
+ useFlagsReady: () => useFlagsReady
29
+ });
30
+ module.exports = __toCommonJS(src_exports);
31
+
32
+ // src/provider.ts
33
+ var import_react = require("react");
34
+ var import_flags = require("@productcraft/flags");
35
+ var FlagsContext = (0, import_react.createContext)(null);
36
+ var onServer = () => typeof globalThis.window === "undefined";
37
+ var Store = class {
38
+ #snap;
39
+ #state;
40
+ #listeners = /* @__PURE__ */ new Set();
41
+ /** What the server rendered: the bootstrap when there is one. */
42
+ server;
43
+ client;
44
+ constructor(client, bootstrap) {
45
+ this.client = client;
46
+ this.#snap = client.snapshot();
47
+ this.#state = client.state;
48
+ this.server = bootstrap == null ? this.#snap : offlineSnapshot(bootstrap);
49
+ }
50
+ subscribe = (listener) => {
51
+ this.#listeners.add(listener);
52
+ return () => this.#listeners.delete(listener);
53
+ };
54
+ get = () => this.#snap;
55
+ ready = () => this.client.state !== "initializing";
56
+ /** Listens to the client; returns the function that stops. Picks up anything that changed before it listened. */
57
+ attach() {
58
+ const update = () => {
59
+ const next = this.client.snapshot();
60
+ if (next.toJSON() === this.#snap.toJSON() && this.client.state === this.#state) return;
61
+ this.#snap = next;
62
+ this.#state = this.client.state;
63
+ for (const l of [...this.#listeners]) l();
64
+ };
65
+ const offs = [this.client.on("configChanged", update), this.client.on("ready", update), this.client.on("error", update)];
66
+ update();
67
+ return () => offs.forEach((off) => off());
68
+ }
69
+ };
70
+ function offlineSnapshot(bootstrap) {
71
+ const c = new import_flags.FlagsClient({ bootstrap, offline: true, logger: null });
72
+ c.close();
73
+ return c.snapshot();
74
+ }
75
+ function build(options, bootstrap) {
76
+ return new import_flags.FlagsClient({ ...options, bootstrap: bootstrap ?? options.bootstrap, ...onServer() ? { offline: true } : null });
77
+ }
78
+ function FlagsProvider(props) {
79
+ const { client: given, options, bootstrap, user, children } = props;
80
+ if (!given && !options) throw new Error("<FlagsProvider> needs a `client` or `options`");
81
+ const [owned, setOwned] = (0, import_react.useState)(() => given ? null : build(options, bootstrap));
82
+ (0, import_react.useEffect)(() => {
83
+ if (given || !owned) return;
84
+ if (owned.state === "closed") return void setOwned(build(options, bootstrap));
85
+ return () => owned.close();
86
+ }, [given, owned]);
87
+ const client = given ?? owned;
88
+ const store = (0, import_react.useMemo)(() => new Store(client, bootstrap), [client]);
89
+ (0, import_react.useEffect)(() => store.attach(), [store]);
90
+ const value = (0, import_react.useMemo)(() => ({ client, store, user }), [client, store, user]);
91
+ return (0, import_react.createElement)(FlagsContext.Provider, { value }, children);
92
+ }
93
+ function useFlagsContext(hook) {
94
+ const ctx = (0, import_react.useContext)(FlagsContext);
95
+ if (!ctx) throw new Error(`${hook}() must be called inside <FlagsProvider>`);
96
+ return ctx;
97
+ }
98
+ var dep = (v) => v !== null && typeof v === "object" ? JSON.stringify(v) : v;
99
+ function useFlag(key, defaultValue, user) {
100
+ return useFlagDetails(key, defaultValue, user).value;
101
+ }
102
+ function useFlagDetails(key, defaultValue, user) {
103
+ const { store, user: fallback } = useFlagsContext("useFlagDetails");
104
+ const snap = (0, import_react.useSyncExternalStore)(store.subscribe, store.get, () => store.server);
105
+ const u = user ?? fallback;
106
+ return (0, import_react.useMemo)(() => snap.getValueDetails(key, defaultValue, u), [snap, key, dep(defaultValue), dep(u)]);
107
+ }
108
+ function useFlagsClient() {
109
+ return useFlagsContext("useFlagsClient").client;
110
+ }
111
+ function useFlagsReady() {
112
+ const { store } = useFlagsContext("useFlagsReady");
113
+ return (0, import_react.useSyncExternalStore)(store.subscribe, store.ready, () => false);
114
+ }
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ FlagsProvider,
118
+ useFlag,
119
+ useFlagDetails,
120
+ useFlagsClient,
121
+ useFlagsReady
122
+ });
123
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/provider.ts"],"sourcesContent":["/**\n * @productcraft/flags-react: React bindings for ProductCraft Flags. `FlagsProvider` holds a\n * FlagsClient (local evaluation; user attributes never leave the app), the hooks read it\n * synchronously and re-render when the config changes. SSR: pass `snapshot().toJSON()` from the\n * server as `bootstrap`.\n *\n * A key used in a browser or mobile app makes its whole config public: keep client flags in their\n * own config, with no internal rules.\n */\nexport { FlagsProvider, useFlag, useFlagDetails, useFlagsClient, useFlagsReady, type FlagDefault, type FlagsProviderProps } from \"./provider.js\";\n","// React bindings for FlagsClient (task 019, design 8.1): one FlagsClient per provider, hooks that\n// read a FlagsSnapshot synchronously, and re-renders on config changes via useSyncExternalStore.\n// SSR: the server renders from `bootstrap` (a `snapshot().toJSON()`), and hydration reads the same\n// bootstrap, so the first client render matches the server HTML. Downloads start after mount.\n\nimport { createContext, createElement, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ReactElement, type ReactNode } from \"react\";\nimport { FlagsClient, type EvaluationDetails, type FlagsClientOptions, type FlagsSnapshot, type FlagValue, type SettingValue, type User } from \"@productcraft/flags\";\n\n/** A default value: booleans, strings and numbers keep their type; objects, arrays and `null` read json settings. */\nexport type FlagDefault = SettingValue | object | null;\n\nexport interface FlagsProviderProps {\n /** A FlagsClient you built and own (the provider never closes it). Give this or `options`, and keep to that choice for the provider's lifetime. */\n client?: FlagsClient;\n /** Options for a FlagsClient the provider builds on mount and closes on unmount. On the server it never downloads. */\n options?: FlagsClientOptions;\n /** A config JSON, usually `snapshot().toJSON()` from the server: the first render (server and hydration) evaluates it. */\n bootstrap?: string | object | null;\n /** The user hooks evaluate for when a hook passes none. */\n user?: User;\n children?: ReactNode;\n}\n\ninterface Ctx {\n client: FlagsClient;\n store: Store;\n user: User | undefined;\n}\n\nconst FlagsContext = createContext<Ctx | null>(null);\nconst onServer = (): boolean => typeof (globalThis as { window?: unknown }).window === \"undefined\";\n\n/** The snapshot hooks read, replaced only when the config or the client state really changed. */\nclass Store {\n #snap: FlagsSnapshot;\n #state: string;\n readonly #listeners = new Set<() => void>();\n /** What the server rendered: the bootstrap when there is one. */\n readonly server: FlagsSnapshot;\n readonly client: FlagsClient;\n\n constructor(client: FlagsClient, bootstrap: string | object | null | undefined) {\n this.client = client;\n this.#snap = client.snapshot();\n this.#state = client.state;\n this.server = bootstrap == null ? this.#snap : offlineSnapshot(bootstrap);\n }\n\n readonly subscribe = (listener: () => void): (() => void) => {\n this.#listeners.add(listener);\n return () => this.#listeners.delete(listener);\n };\n\n readonly get = (): FlagsSnapshot => this.#snap;\n\n readonly ready = (): boolean => this.client.state !== \"initializing\";\n\n /** Listens to the client; returns the function that stops. Picks up anything that changed before it listened. */\n attach(): () => void {\n const update = (): void => {\n const next = this.client.snapshot();\n if (next.toJSON() === this.#snap.toJSON() && this.client.state === this.#state) return;\n this.#snap = next;\n this.#state = this.client.state;\n for (const l of [...this.#listeners]) l();\n };\n const offs = [this.client.on(\"configChanged\", update), this.client.on(\"ready\", update), this.client.on(\"error\", update)];\n update();\n return () => offs.forEach((off) => off());\n }\n}\n\nfunction offlineSnapshot(bootstrap: string | object): FlagsSnapshot {\n const c = new FlagsClient({ bootstrap, offline: true, logger: null });\n c.close();\n return c.snapshot();\n}\n\nfunction build(options: FlagsClientOptions, bootstrap: string | object | null | undefined): FlagsClient {\n return new FlagsClient({ ...options, bootstrap: bootstrap ?? options.bootstrap, ...(onServer() ? { offline: true } : null) });\n}\n\n/**\n * Makes a FlagsClient available to the hooks below it.\n * @example\n * ```tsx\n * <FlagsProvider options={{ sdkKey: \"pcf_sdk_…\" }} user={{ identifier: user.id }}>\n * <App />\n * </FlagsProvider>\n * ```\n */\nexport function FlagsProvider(props: FlagsProviderProps): ReactElement {\n const { client: given, options, bootstrap, user, children } = props;\n if (!given && !options) throw new Error(\"<FlagsProvider> needs a `client` or `options`\");\n const [owned, setOwned] = useState<FlagsClient | null>(() => (given ? null : build(options!, bootstrap)));\n useEffect(() => {\n if (given || !owned) return;\n // React StrictMode unmounts and remounts once in development: replace the client that unmount closed.\n if (owned.state === \"closed\") return void setOwned(build(options!, bootstrap));\n return () => owned.close();\n // `options` and `bootstrap` are read once, like useState's initial value.\n }, [given, owned]);\n const client = given ?? owned!;\n const store = useMemo(() => new Store(client, bootstrap), [client]);\n useEffect(() => store.attach(), [store]);\n const value = useMemo<Ctx>(() => ({ client, store, user }), [client, store, user]);\n return createElement(FlagsContext.Provider, { value }, children);\n}\n\nfunction useFlagsContext(hook: string): Ctx {\n const ctx = useContext(FlagsContext);\n if (!ctx) throw new Error(`${hook}() must be called inside <FlagsProvider>`);\n return ctx;\n}\n\n/** A stable dependency for a default or user that callers usually write inline. */\nconst dep = (v: unknown): unknown => (v !== null && typeof v === \"object\" ? JSON.stringify(v) : v);\n\n/** The value of a flag or setting, evaluated locally; `defaultValue` until a config is there, or on any failure. Re-renders when the config changes. */\nexport function useFlag<D extends FlagDefault>(key: string, defaultValue: D, user?: User | null): FlagValue<D> {\n return useFlagDetails(key, defaultValue, user).value;\n}\n\n/** The value plus why (reason, matched rule or split, error code, revision). */\nexport function useFlagDetails<D extends FlagDefault>(key: string, defaultValue: D, user?: User | null): EvaluationDetails<FlagValue<D>> {\n const { store, user: fallback } = useFlagsContext(\"useFlagDetails\");\n const snap = useSyncExternalStore(store.subscribe, store.get, () => store.server);\n const u = user ?? fallback;\n return useMemo(() => snap.getValueDetails(key, defaultValue, u), [snap, key, dep(defaultValue), dep(u)]);\n}\n\n/** The provider's FlagsClient (for `getAllValues`, `forceRefresh`, events). */\nexport function useFlagsClient(): FlagsClient {\n return useFlagsContext(\"useFlagsClient\").client;\n}\n\n/** False until the client's start-up settled (first download, or `maxInitWaitSeconds`); always false while rendering on the server. */\nexport function useFlagsReady(): boolean {\n const { store } = useFlagsContext(\"useFlagsReady\");\n return useSyncExternalStore(store.subscribe, store.ready, () => false);\n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KAAK,UAAU,CAAC,IAAI;AAGzF,SAAS,QAA+B,KAAa,cAAiB,MAAkC;AAC7G,SAAO,eAAe,KAAK,cAAc,IAAI,EAAE;AACjD;AAGO,SAAS,eAAsC,KAAa,cAAiB,MAAqD;AACvI,QAAM,EAAE,OAAO,MAAM,SAAS,IAAI,gBAAgB,gBAAgB;AAClE,QAAM,WAAO,mCAAqB,MAAM,WAAW,MAAM,KAAK,MAAM,MAAM,MAAM;AAChF,QAAM,IAAI,QAAQ;AAClB,aAAO,sBAAQ,MAAM,KAAK,gBAAgB,KAAK,cAAc,CAAC,GAAG,CAAC,MAAM,KAAK,IAAI,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC;AACzG;AAGO,SAAS,iBAA8B;AAC5C,SAAO,gBAAgB,gBAAgB,EAAE;AAC3C;AAGO,SAAS,gBAAyB;AACvC,QAAM,EAAE,MAAM,IAAI,gBAAgB,eAAe;AACjD,aAAO,mCAAqB,MAAM,WAAW,MAAM,OAAO,MAAM,KAAK;AACvE;","names":[]}
@@ -0,0 +1,36 @@
1
+ import { ReactNode, ReactElement } from 'react';
2
+ import { SettingValue, FlagsClient, FlagsClientOptions, User, FlagValue, EvaluationDetails } from '@productcraft/flags';
3
+
4
+ /** A default value: booleans, strings and numbers keep their type; objects, arrays and `null` read json settings. */
5
+ type FlagDefault = SettingValue | object | null;
6
+ interface FlagsProviderProps {
7
+ /** A FlagsClient you built and own (the provider never closes it). Give this or `options`, and keep to that choice for the provider's lifetime. */
8
+ client?: FlagsClient;
9
+ /** Options for a FlagsClient the provider builds on mount and closes on unmount. On the server it never downloads. */
10
+ options?: FlagsClientOptions;
11
+ /** A config JSON, usually `snapshot().toJSON()` from the server: the first render (server and hydration) evaluates it. */
12
+ bootstrap?: string | object | null;
13
+ /** The user hooks evaluate for when a hook passes none. */
14
+ user?: User;
15
+ children?: ReactNode;
16
+ }
17
+ /**
18
+ * Makes a FlagsClient available to the hooks below it.
19
+ * @example
20
+ * ```tsx
21
+ * <FlagsProvider options={{ sdkKey: "pcf_sdk_…" }} user={{ identifier: user.id }}>
22
+ * <App />
23
+ * </FlagsProvider>
24
+ * ```
25
+ */
26
+ declare function FlagsProvider(props: FlagsProviderProps): ReactElement;
27
+ /** The value of a flag or setting, evaluated locally; `defaultValue` until a config is there, or on any failure. Re-renders when the config changes. */
28
+ declare function useFlag<D extends FlagDefault>(key: string, defaultValue: D, user?: User | null): FlagValue<D>;
29
+ /** The value plus why (reason, matched rule or split, error code, revision). */
30
+ declare function useFlagDetails<D extends FlagDefault>(key: string, defaultValue: D, user?: User | null): EvaluationDetails<FlagValue<D>>;
31
+ /** The provider's FlagsClient (for `getAllValues`, `forceRefresh`, events). */
32
+ declare function useFlagsClient(): FlagsClient;
33
+ /** False until the client's start-up settled (first download, or `maxInitWaitSeconds`); always false while rendering on the server. */
34
+ declare function useFlagsReady(): boolean;
35
+
36
+ export { type FlagDefault, FlagsProvider, type FlagsProviderProps, useFlag, useFlagDetails, useFlagsClient, useFlagsReady };
@@ -0,0 +1,36 @@
1
+ import { ReactNode, ReactElement } from 'react';
2
+ import { SettingValue, FlagsClient, FlagsClientOptions, User, FlagValue, EvaluationDetails } from '@productcraft/flags';
3
+
4
+ /** A default value: booleans, strings and numbers keep their type; objects, arrays and `null` read json settings. */
5
+ type FlagDefault = SettingValue | object | null;
6
+ interface FlagsProviderProps {
7
+ /** A FlagsClient you built and own (the provider never closes it). Give this or `options`, and keep to that choice for the provider's lifetime. */
8
+ client?: FlagsClient;
9
+ /** Options for a FlagsClient the provider builds on mount and closes on unmount. On the server it never downloads. */
10
+ options?: FlagsClientOptions;
11
+ /** A config JSON, usually `snapshot().toJSON()` from the server: the first render (server and hydration) evaluates it. */
12
+ bootstrap?: string | object | null;
13
+ /** The user hooks evaluate for when a hook passes none. */
14
+ user?: User;
15
+ children?: ReactNode;
16
+ }
17
+ /**
18
+ * Makes a FlagsClient available to the hooks below it.
19
+ * @example
20
+ * ```tsx
21
+ * <FlagsProvider options={{ sdkKey: "pcf_sdk_…" }} user={{ identifier: user.id }}>
22
+ * <App />
23
+ * </FlagsProvider>
24
+ * ```
25
+ */
26
+ declare function FlagsProvider(props: FlagsProviderProps): ReactElement;
27
+ /** The value of a flag or setting, evaluated locally; `defaultValue` until a config is there, or on any failure. Re-renders when the config changes. */
28
+ declare function useFlag<D extends FlagDefault>(key: string, defaultValue: D, user?: User | null): FlagValue<D>;
29
+ /** The value plus why (reason, matched rule or split, error code, revision). */
30
+ declare function useFlagDetails<D extends FlagDefault>(key: string, defaultValue: D, user?: User | null): EvaluationDetails<FlagValue<D>>;
31
+ /** The provider's FlagsClient (for `getAllValues`, `forceRefresh`, events). */
32
+ declare function useFlagsClient(): FlagsClient;
33
+ /** False until the client's start-up settled (first download, or `maxInitWaitSeconds`); always false while rendering on the server. */
34
+ declare function useFlagsReady(): boolean;
35
+
36
+ export { type FlagDefault, FlagsProvider, type FlagsProviderProps, useFlag, useFlagDetails, useFlagsClient, useFlagsReady };
package/dist/index.js ADDED
@@ -0,0 +1,93 @@
1
+ "use client";
2
+
3
+ // src/provider.ts
4
+ import { createContext, createElement, useContext, useEffect, useMemo, useState, useSyncExternalStore } from "react";
5
+ import { FlagsClient } from "@productcraft/flags";
6
+ var FlagsContext = createContext(null);
7
+ var onServer = () => typeof globalThis.window === "undefined";
8
+ var Store = class {
9
+ #snap;
10
+ #state;
11
+ #listeners = /* @__PURE__ */ new Set();
12
+ /** What the server rendered: the bootstrap when there is one. */
13
+ server;
14
+ client;
15
+ constructor(client, bootstrap) {
16
+ this.client = client;
17
+ this.#snap = client.snapshot();
18
+ this.#state = client.state;
19
+ this.server = bootstrap == null ? this.#snap : offlineSnapshot(bootstrap);
20
+ }
21
+ subscribe = (listener) => {
22
+ this.#listeners.add(listener);
23
+ return () => this.#listeners.delete(listener);
24
+ };
25
+ get = () => this.#snap;
26
+ ready = () => this.client.state !== "initializing";
27
+ /** Listens to the client; returns the function that stops. Picks up anything that changed before it listened. */
28
+ attach() {
29
+ const update = () => {
30
+ const next = this.client.snapshot();
31
+ if (next.toJSON() === this.#snap.toJSON() && this.client.state === this.#state) return;
32
+ this.#snap = next;
33
+ this.#state = this.client.state;
34
+ for (const l of [...this.#listeners]) l();
35
+ };
36
+ const offs = [this.client.on("configChanged", update), this.client.on("ready", update), this.client.on("error", update)];
37
+ update();
38
+ return () => offs.forEach((off) => off());
39
+ }
40
+ };
41
+ function offlineSnapshot(bootstrap) {
42
+ const c = new FlagsClient({ bootstrap, offline: true, logger: null });
43
+ c.close();
44
+ return c.snapshot();
45
+ }
46
+ function build(options, bootstrap) {
47
+ return new FlagsClient({ ...options, bootstrap: bootstrap ?? options.bootstrap, ...onServer() ? { offline: true } : null });
48
+ }
49
+ function FlagsProvider(props) {
50
+ const { client: given, options, bootstrap, user, children } = props;
51
+ if (!given && !options) throw new Error("<FlagsProvider> needs a `client` or `options`");
52
+ const [owned, setOwned] = useState(() => given ? null : build(options, bootstrap));
53
+ useEffect(() => {
54
+ if (given || !owned) return;
55
+ if (owned.state === "closed") return void setOwned(build(options, bootstrap));
56
+ return () => owned.close();
57
+ }, [given, owned]);
58
+ const client = given ?? owned;
59
+ const store = useMemo(() => new Store(client, bootstrap), [client]);
60
+ useEffect(() => store.attach(), [store]);
61
+ const value = useMemo(() => ({ client, store, user }), [client, store, user]);
62
+ return createElement(FlagsContext.Provider, { value }, children);
63
+ }
64
+ function useFlagsContext(hook) {
65
+ const ctx = useContext(FlagsContext);
66
+ if (!ctx) throw new Error(`${hook}() must be called inside <FlagsProvider>`);
67
+ return ctx;
68
+ }
69
+ var dep = (v) => v !== null && typeof v === "object" ? JSON.stringify(v) : v;
70
+ function useFlag(key, defaultValue, user) {
71
+ return useFlagDetails(key, defaultValue, user).value;
72
+ }
73
+ function useFlagDetails(key, defaultValue, user) {
74
+ const { store, user: fallback } = useFlagsContext("useFlagDetails");
75
+ const snap = useSyncExternalStore(store.subscribe, store.get, () => store.server);
76
+ const u = user ?? fallback;
77
+ return useMemo(() => snap.getValueDetails(key, defaultValue, u), [snap, key, dep(defaultValue), dep(u)]);
78
+ }
79
+ function useFlagsClient() {
80
+ return useFlagsContext("useFlagsClient").client;
81
+ }
82
+ function useFlagsReady() {
83
+ const { store } = useFlagsContext("useFlagsReady");
84
+ return useSyncExternalStore(store.subscribe, store.ready, () => false);
85
+ }
86
+ export {
87
+ FlagsProvider,
88
+ useFlag,
89
+ useFlagDetails,
90
+ useFlagsClient,
91
+ useFlagsReady
92
+ };
93
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/provider.ts"],"sourcesContent":["// React bindings for FlagsClient (task 019, design 8.1): one FlagsClient per provider, hooks that\n// read a FlagsSnapshot synchronously, and re-renders on config changes via useSyncExternalStore.\n// SSR: the server renders from `bootstrap` (a `snapshot().toJSON()`), and hydration reads the same\n// bootstrap, so the first client render matches the server HTML. Downloads start after mount.\n\nimport { createContext, createElement, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ReactElement, type ReactNode } from \"react\";\nimport { FlagsClient, type EvaluationDetails, type FlagsClientOptions, type FlagsSnapshot, type FlagValue, type SettingValue, type User } from \"@productcraft/flags\";\n\n/** A default value: booleans, strings and numbers keep their type; objects, arrays and `null` read json settings. */\nexport type FlagDefault = SettingValue | object | null;\n\nexport interface FlagsProviderProps {\n /** A FlagsClient you built and own (the provider never closes it). Give this or `options`, and keep to that choice for the provider's lifetime. */\n client?: FlagsClient;\n /** Options for a FlagsClient the provider builds on mount and closes on unmount. On the server it never downloads. */\n options?: FlagsClientOptions;\n /** A config JSON, usually `snapshot().toJSON()` from the server: the first render (server and hydration) evaluates it. */\n bootstrap?: string | object | null;\n /** The user hooks evaluate for when a hook passes none. */\n user?: User;\n children?: ReactNode;\n}\n\ninterface Ctx {\n client: FlagsClient;\n store: Store;\n user: User | undefined;\n}\n\nconst FlagsContext = createContext<Ctx | null>(null);\nconst onServer = (): boolean => typeof (globalThis as { window?: unknown }).window === \"undefined\";\n\n/** The snapshot hooks read, replaced only when the config or the client state really changed. */\nclass Store {\n #snap: FlagsSnapshot;\n #state: string;\n readonly #listeners = new Set<() => void>();\n /** What the server rendered: the bootstrap when there is one. */\n readonly server: FlagsSnapshot;\n readonly client: FlagsClient;\n\n constructor(client: FlagsClient, bootstrap: string | object | null | undefined) {\n this.client = client;\n this.#snap = client.snapshot();\n this.#state = client.state;\n this.server = bootstrap == null ? this.#snap : offlineSnapshot(bootstrap);\n }\n\n readonly subscribe = (listener: () => void): (() => void) => {\n this.#listeners.add(listener);\n return () => this.#listeners.delete(listener);\n };\n\n readonly get = (): FlagsSnapshot => this.#snap;\n\n readonly ready = (): boolean => this.client.state !== \"initializing\";\n\n /** Listens to the client; returns the function that stops. Picks up anything that changed before it listened. */\n attach(): () => void {\n const update = (): void => {\n const next = this.client.snapshot();\n if (next.toJSON() === this.#snap.toJSON() && this.client.state === this.#state) return;\n this.#snap = next;\n this.#state = this.client.state;\n for (const l of [...this.#listeners]) l();\n };\n const offs = [this.client.on(\"configChanged\", update), this.client.on(\"ready\", update), this.client.on(\"error\", update)];\n update();\n return () => offs.forEach((off) => off());\n }\n}\n\nfunction offlineSnapshot(bootstrap: string | object): FlagsSnapshot {\n const c = new FlagsClient({ bootstrap, offline: true, logger: null });\n c.close();\n return c.snapshot();\n}\n\nfunction build(options: FlagsClientOptions, bootstrap: string | object | null | undefined): FlagsClient {\n return new FlagsClient({ ...options, bootstrap: bootstrap ?? options.bootstrap, ...(onServer() ? { offline: true } : null) });\n}\n\n/**\n * Makes a FlagsClient available to the hooks below it.\n * @example\n * ```tsx\n * <FlagsProvider options={{ sdkKey: \"pcf_sdk_…\" }} user={{ identifier: user.id }}>\n * <App />\n * </FlagsProvider>\n * ```\n */\nexport function FlagsProvider(props: FlagsProviderProps): ReactElement {\n const { client: given, options, bootstrap, user, children } = props;\n if (!given && !options) throw new Error(\"<FlagsProvider> needs a `client` or `options`\");\n const [owned, setOwned] = useState<FlagsClient | null>(() => (given ? null : build(options!, bootstrap)));\n useEffect(() => {\n if (given || !owned) return;\n // React StrictMode unmounts and remounts once in development: replace the client that unmount closed.\n if (owned.state === \"closed\") return void setOwned(build(options!, bootstrap));\n return () => owned.close();\n // `options` and `bootstrap` are read once, like useState's initial value.\n }, [given, owned]);\n const client = given ?? owned!;\n const store = useMemo(() => new Store(client, bootstrap), [client]);\n useEffect(() => store.attach(), [store]);\n const value = useMemo<Ctx>(() => ({ client, store, user }), [client, store, user]);\n return createElement(FlagsContext.Provider, { value }, children);\n}\n\nfunction useFlagsContext(hook: string): Ctx {\n const ctx = useContext(FlagsContext);\n if (!ctx) throw new Error(`${hook}() must be called inside <FlagsProvider>`);\n return ctx;\n}\n\n/** A stable dependency for a default or user that callers usually write inline. */\nconst dep = (v: unknown): unknown => (v !== null && typeof v === \"object\" ? JSON.stringify(v) : v);\n\n/** The value of a flag or setting, evaluated locally; `defaultValue` until a config is there, or on any failure. Re-renders when the config changes. */\nexport function useFlag<D extends FlagDefault>(key: string, defaultValue: D, user?: User | null): FlagValue<D> {\n return useFlagDetails(key, defaultValue, user).value;\n}\n\n/** The value plus why (reason, matched rule or split, error code, revision). */\nexport function useFlagDetails<D extends FlagDefault>(key: string, defaultValue: D, user?: User | null): EvaluationDetails<FlagValue<D>> {\n const { store, user: fallback } = useFlagsContext(\"useFlagDetails\");\n const snap = useSyncExternalStore(store.subscribe, store.get, () => store.server);\n const u = user ?? fallback;\n return useMemo(() => snap.getValueDetails(key, defaultValue, u), [snap, key, dep(defaultValue), dep(u)]);\n}\n\n/** The provider's FlagsClient (for `getAllValues`, `forceRefresh`, events). */\nexport function useFlagsClient(): FlagsClient {\n return useFlagsContext(\"useFlagsClient\").client;\n}\n\n/** False until the client's start-up settled (first download, or `maxInitWaitSeconds`); always false while rendering on the server. */\nexport function useFlagsReady(): boolean {\n const { store } = useFlagsContext(\"useFlagsReady\");\n return useSyncExternalStore(store.subscribe, store.ready, () => false);\n}\n"],"mappings":";;;AAKA,SAAS,eAAe,eAAe,YAAY,WAAW,SAAS,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EAAE;AACjD;AAGO,SAAS,eAAsC,KAAa,cAAiB,MAAqD;AACvI,QAAM,EAAE,OAAO,MAAM,SAAS,IAAI,gBAAgB,gBAAgB;AAClE,QAAM,OAAO,qBAAqB,MAAM,WAAW,MAAM,KAAK,MAAM,MAAM,MAAM;AAChF,QAAM,IAAI,QAAQ;AAClB,SAAO,QAAQ,MAAM,KAAK,gBAAgB,KAAK,cAAc,CAAC,GAAG,CAAC,MAAM,KAAK,IAAI,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC;AACzG;AAGO,SAAS,iBAA8B;AAC5C,SAAO,gBAAgB,gBAAgB,EAAE;AAC3C;AAGO,SAAS,gBAAyB;AACvC,QAAM,EAAE,MAAM,IAAI,gBAAgB,eAAe;AACjD,SAAO,qBAAqB,MAAM,WAAW,MAAM,OAAO,MAAM,KAAK;AACvE;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@productcraft/flags-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "React bindings for ProductCraft Flags: FlagsProvider, useFlag and SSR bootstrap (Next.js App and Pages Router) over FlagsClient's local evaluation. A key used in a browser or mobile app makes its whole config public, so client flags belong in their own config with no internal rules.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist/**",
23
+ "README.md",
24
+ "LICENSE"
25
+ ],
26
+ "sideEffects": false,
27
+ "engines": {
28
+ "node": ">=20.3"
29
+ },
30
+ "keywords": [
31
+ "productcraft",
32
+ "sdk",
33
+ "react",
34
+ "nextjs",
35
+ "feature-flags",
36
+ "feature-toggles",
37
+ "remote-config"
38
+ ],
39
+ "author": "ProductCraft",
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/clauderanelagh/productcraft-node.git",
44
+ "directory": "packages/flags-react"
45
+ },
46
+ "homepage": "https://productcraft.co/docs/flags",
47
+ "bugs": {
48
+ "url": "https://github.com/clauderanelagh/productcraft-node/issues"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public",
52
+ "provenance": true
53
+ },
54
+ "peerDependencies": {
55
+ "@productcraft/flags": "^0.1.0 || ^0.2.0 || ^1.0.0",
56
+ "react": ">=18.0.0"
57
+ },
58
+ "devDependencies": {
59
+ "@types/react": "19.3.0",
60
+ "@types/react-dom": "19.3.0",
61
+ "jsdom": "31.0.0",
62
+ "react": "19.3.1",
63
+ "react-dom": "19.3.1",
64
+ "@productcraft/flags": "0.2.0"
65
+ },
66
+ "scripts": {
67
+ "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
68
+ "test": "tsc -p tests/tsconfig.json && vitest run"
69
+ }
6
70
  }