@flagdown/react 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. package/README.md +11 -1
  2. package/dist/index.js +13 -4
  3. package/package.json +5 -3
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Use the `Feature` component to switch between new UI and a fallback in React 18+.
4
4
 
5
5
  ```sh
6
- npm install @flagdown/react@0.0.4
6
+ npm install @flagdown/react@0.0.5
7
7
  ```
8
8
 
9
9
  ```tsx
@@ -57,3 +57,13 @@ apps using it. Client-side flags are not an authorization boundary.
57
57
  are internal; the package exposes no flag hooks or direct evaluation functions.
58
58
  Use `FlagdownProvider` to configure your project. A provider without project
59
59
  configuration renders each feature's fallback.
60
+
61
+ API transport types are generated from `openapi/flagdown-api.json` with
62
+ `openapi-typescript` before SDK typechecking and building. They stay internal;
63
+ the public exports remain `Feature`, `FlagdownProvider` and their prop types.
64
+ The runtime still rejects malformed or non-boolean flag values.
65
+
66
+ For SDK development, run `npm run --workspace @flagdown/react generate:types`
67
+ to regenerate `src/generated/api.d.ts`. This file is ignored by git and is never
68
+ the source of truth. Backend CI checks candidate contracts against the current
69
+ SDK before publishing the generated specification to this repository.
package/dist/index.js CHANGED
@@ -21,19 +21,28 @@ var disabledFlagEvaluator = {
21
21
  isEnabled: () => false
22
22
  };
23
23
 
24
+ // src/api-types.ts
25
+ var clientFlagsPath = "/v1/client/flags";
26
+
24
27
  // src/remote.ts
25
28
  async function fetchFlagState(apiUrl, clientToken, signal) {
26
- const response = await fetch(apiUrl.replace(/\/$/, "") + "/v1/client/flags", {
27
- headers: { "x-flagdown-client-token": clientToken },
29
+ const headers = { "x-flagdown-client-token": clientToken };
30
+ const response = await fetch(apiUrl.replace(/\/$/, "") + clientFlagsPath, {
31
+ headers,
28
32
  cache: "no-store",
29
33
  signal
30
34
  });
31
35
  if (!response.ok) throw new Error(`Flagdown request failed (${response.status})`);
32
36
  const data = await response.json();
33
- if (!data || typeof data !== "object" || !("flags" in data) || !data.flags || typeof data.flags !== "object" || Array.isArray(data.flags) || Object.values(data.flags).some((value) => typeof value !== "boolean")) {
37
+ if (!data || typeof data !== "object" || !("flags" in data) || !data.flags || typeof data.flags !== "object" || Array.isArray(data.flags)) {
34
38
  throw new Error("Invalid Flagdown response");
35
39
  }
36
- return data.flags;
40
+ const flags = Object.fromEntries(Object.entries(data.flags).map(([key, enabled]) => {
41
+ if (typeof enabled !== "boolean") throw new Error("Invalid Flagdown response");
42
+ return [key, enabled];
43
+ }));
44
+ const result = { flags };
45
+ return result.flags;
37
46
  }
38
47
 
39
48
  // src/FlagdownProvider.tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flagdown/react",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "React SDK for evaluating Flagdown feature flags.",
@@ -28,9 +28,10 @@
28
28
  "LICENSE"
29
29
  ],
30
30
  "scripts": {
31
- "build": "tsup src/index.ts --format esm --dts --clean",
31
+ "generate:types": "node scripts/generate-api-types.mjs",
32
+ "build": "node scripts/generate-api-types.mjs && tsup src/index.ts --format esm --dts --clean",
32
33
  "test": "bun test",
33
- "typecheck": "tsc --noEmit"
34
+ "typecheck": "node scripts/generate-api-types.mjs && tsc --noEmit"
34
35
  },
35
36
  "peerDependencies": {
36
37
  "react": ">=18",
@@ -38,6 +39,7 @@
38
39
  },
39
40
  "devDependencies": {
40
41
  "@types/react": "^18",
42
+ "openapi-typescript": "7.13.0",
41
43
  "react": "^18",
42
44
  "react-dom": "^18",
43
45
  "tsup": "^8",