@smooai/config 3.0.0 → 3.0.1

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.
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Next.js config helper that injects feature flags as NEXT_PUBLIC_ environment variables.
3
+ *
4
+ * This allows client components to read feature flags via `getClientFeatureFlag()`
5
+ * from `@smooai/config/feature-flags` without importing any Node.js-dependent code.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // next.config.ts
10
+ * import { withFeatureFlags } from '@smooai/config/nextjs/withFeatureFlags';
11
+ * import defaultConfig from './.smooai-config/default';
12
+ * import developmentConfig from './.smooai-config/development';
13
+ *
14
+ * const nextConfig = withFeatureFlags({
15
+ * default: defaultConfig,
16
+ * development: developmentConfig,
17
+ * });
18
+ *
19
+ * export default nextConfig;
20
+ * ```
21
+ *
22
+ * This will set environment variables like:
23
+ * - NEXT_PUBLIC_FEATURE_FLAG_ABOUT_PAGE=true (in development)
24
+ * - NEXT_PUBLIC_FEATURE_FLAG_ABOUT_PAGE=false (in production)
25
+ *
26
+ * Then in any client component:
27
+ * ```tsx
28
+ * import { getClientFeatureFlag } from '@smooai/config/feature-flags';
29
+ * const isEnabled = getClientFeatureFlag('aboutPage');
30
+ * ```
31
+ */
32
+ type NextConfig = Record<string, unknown>;
33
+ type FeatureFlagConfig = Record<string, boolean>;
34
+ interface WithFeatureFlagsOptions {
35
+ /** Default feature flag values (used in production). */
36
+ default: FeatureFlagConfig;
37
+ /** Development overrides (merged with default). */
38
+ development?: FeatureFlagConfig;
39
+ /** Additional stage-specific overrides. Key is the stage name. */
40
+ [stage: string]: FeatureFlagConfig | undefined;
41
+ }
42
+ /**
43
+ * Wraps a Next.js config to inject feature flags as NEXT_PUBLIC_ environment variables.
44
+ *
45
+ * Reads `NEXT_PUBLIC_SST_STAGE` (or `NODE_ENV`) to determine which config to use.
46
+ * Falls back to development config if stage is not 'production'.
47
+ */
48
+ declare function withFeatureFlags(flagConfigs: WithFeatureFlagsOptions, nextConfig?: NextConfig): NextConfig;
49
+
50
+ export { withFeatureFlags };
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Next.js config helper that injects feature flags as NEXT_PUBLIC_ environment variables.
3
+ *
4
+ * This allows client components to read feature flags via `getClientFeatureFlag()`
5
+ * from `@smooai/config/feature-flags` without importing any Node.js-dependent code.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // next.config.ts
10
+ * import { withFeatureFlags } from '@smooai/config/nextjs/withFeatureFlags';
11
+ * import defaultConfig from './.smooai-config/default';
12
+ * import developmentConfig from './.smooai-config/development';
13
+ *
14
+ * const nextConfig = withFeatureFlags({
15
+ * default: defaultConfig,
16
+ * development: developmentConfig,
17
+ * });
18
+ *
19
+ * export default nextConfig;
20
+ * ```
21
+ *
22
+ * This will set environment variables like:
23
+ * - NEXT_PUBLIC_FEATURE_FLAG_ABOUT_PAGE=true (in development)
24
+ * - NEXT_PUBLIC_FEATURE_FLAG_ABOUT_PAGE=false (in production)
25
+ *
26
+ * Then in any client component:
27
+ * ```tsx
28
+ * import { getClientFeatureFlag } from '@smooai/config/feature-flags';
29
+ * const isEnabled = getClientFeatureFlag('aboutPage');
30
+ * ```
31
+ */
32
+ type NextConfig = Record<string, unknown>;
33
+ type FeatureFlagConfig = Record<string, boolean>;
34
+ interface WithFeatureFlagsOptions {
35
+ /** Default feature flag values (used in production). */
36
+ default: FeatureFlagConfig;
37
+ /** Development overrides (merged with default). */
38
+ development?: FeatureFlagConfig;
39
+ /** Additional stage-specific overrides. Key is the stage name. */
40
+ [stage: string]: FeatureFlagConfig | undefined;
41
+ }
42
+ /**
43
+ * Wraps a Next.js config to inject feature flags as NEXT_PUBLIC_ environment variables.
44
+ *
45
+ * Reads `NEXT_PUBLIC_SST_STAGE` (or `NODE_ENV`) to determine which config to use.
46
+ * Falls back to development config if stage is not 'production'.
47
+ */
48
+ declare function withFeatureFlags(flagConfigs: WithFeatureFlagsOptions, nextConfig?: NextConfig): NextConfig;
49
+
50
+ export { withFeatureFlags };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/nextjs/withFeatureFlags.ts
21
+ var withFeatureFlags_exports = {};
22
+ __export(withFeatureFlags_exports, {
23
+ withFeatureFlags: () => withFeatureFlags
24
+ });
25
+ module.exports = __toCommonJS(withFeatureFlags_exports);
26
+ function toUpperSnakeCase(key) {
27
+ return key.replace(/([A-Z])/g, "_$1").toUpperCase();
28
+ }
29
+ function withFeatureFlags(flagConfigs, nextConfig = {}) {
30
+ const stage = process.env.NEXT_PUBLIC_SST_STAGE ?? (process.env.NODE_ENV === "production" ? "production" : "development");
31
+ const defaultFlags = flagConfigs.default ?? {};
32
+ const stageOverrides = flagConfigs[stage] ?? {};
33
+ const resolvedFlags = { ...defaultFlags, ...stageOverrides };
34
+ const env = {};
35
+ for (const [key, value] of Object.entries(resolvedFlags)) {
36
+ const envKey = `NEXT_PUBLIC_FEATURE_FLAG_${toUpperSnakeCase(key)}`;
37
+ env[envKey] = String(value);
38
+ process.env[envKey] = String(value);
39
+ }
40
+ return {
41
+ ...nextConfig,
42
+ env: {
43
+ ...nextConfig.env,
44
+ ...env
45
+ }
46
+ };
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ withFeatureFlags
51
+ });
52
+ //# sourceMappingURL=withFeatureFlags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/nextjs/withFeatureFlags.ts"],"sourcesContent":["/**\n * Next.js config helper that injects feature flags as NEXT_PUBLIC_ environment variables.\n *\n * This allows client components to read feature flags via `getClientFeatureFlag()`\n * from `@smooai/config/feature-flags` without importing any Node.js-dependent code.\n *\n * @example\n * ```ts\n * // next.config.ts\n * import { withFeatureFlags } from '@smooai/config/nextjs/withFeatureFlags';\n * import defaultConfig from './.smooai-config/default';\n * import developmentConfig from './.smooai-config/development';\n *\n * const nextConfig = withFeatureFlags({\n * default: defaultConfig,\n * development: developmentConfig,\n * });\n *\n * export default nextConfig;\n * ```\n *\n * This will set environment variables like:\n * - NEXT_PUBLIC_FEATURE_FLAG_ABOUT_PAGE=true (in development)\n * - NEXT_PUBLIC_FEATURE_FLAG_ABOUT_PAGE=false (in production)\n *\n * Then in any client component:\n * ```tsx\n * import { getClientFeatureFlag } from '@smooai/config/feature-flags';\n * const isEnabled = getClientFeatureFlag('aboutPage');\n * ```\n */\n\ntype NextConfig = Record<string, unknown>;\ntype FeatureFlagConfig = Record<string, boolean>;\n\ninterface WithFeatureFlagsOptions {\n /** Default feature flag values (used in production). */\n default: FeatureFlagConfig;\n /** Development overrides (merged with default). */\n development?: FeatureFlagConfig;\n /** Additional stage-specific overrides. Key is the stage name. */\n [stage: string]: FeatureFlagConfig | undefined;\n}\n\n/**\n * Convert a camelCase key to UPPER_SNAKE_CASE.\n * e.g., \"aboutPage\" → \"ABOUT_PAGE\"\n */\nfunction toUpperSnakeCase(key: string): string {\n return key.replace(/([A-Z])/g, '_$1').toUpperCase();\n}\n\n/**\n * Wraps a Next.js config to inject feature flags as NEXT_PUBLIC_ environment variables.\n *\n * Reads `NEXT_PUBLIC_SST_STAGE` (or `NODE_ENV`) to determine which config to use.\n * Falls back to development config if stage is not 'production'.\n */\nexport function withFeatureFlags(flagConfigs: WithFeatureFlagsOptions, nextConfig: NextConfig = {}): NextConfig {\n const stage = process.env.NEXT_PUBLIC_SST_STAGE ?? (process.env.NODE_ENV === 'production' ? 'production' : 'development');\n\n // Merge default with stage-specific overrides\n const defaultFlags = flagConfigs.default ?? {};\n const stageOverrides = flagConfigs[stage] ?? {};\n const resolvedFlags: FeatureFlagConfig = { ...defaultFlags, ...stageOverrides };\n\n // Inject as NEXT_PUBLIC_ env vars\n const env: Record<string, string> = {};\n for (const [key, value] of Object.entries(resolvedFlags)) {\n const envKey = `NEXT_PUBLIC_FEATURE_FLAG_${toUpperSnakeCase(key)}`;\n env[envKey] = String(value);\n // Also set in process.env for SSR\n process.env[envKey] = String(value);\n }\n\n return {\n ...nextConfig,\n env: {\n ...(nextConfig.env as Record<string, string> | undefined),\n ...env,\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgDA,SAAS,iBAAiB,KAAqB;AAC3C,SAAO,IAAI,QAAQ,YAAY,KAAK,EAAE,YAAY;AACtD;AAQO,SAAS,iBAAiB,aAAsC,aAAyB,CAAC,GAAe;AAC5G,QAAM,QAAQ,QAAQ,IAAI,0BAA0B,QAAQ,IAAI,aAAa,eAAe,eAAe;AAG3G,QAAM,eAAe,YAAY,WAAW,CAAC;AAC7C,QAAM,iBAAiB,YAAY,KAAK,KAAK,CAAC;AAC9C,QAAM,gBAAmC,EAAE,GAAG,cAAc,GAAG,eAAe;AAG9E,QAAM,MAA8B,CAAC;AACrC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,aAAa,GAAG;AACtD,UAAM,SAAS,4BAA4B,iBAAiB,GAAG,CAAC;AAChE,QAAI,MAAM,IAAI,OAAO,KAAK;AAE1B,YAAQ,IAAI,MAAM,IAAI,OAAO,KAAK;AAAA,EACtC;AAEA,SAAO;AAAA,IACH,GAAG;AAAA,IACH,KAAK;AAAA,MACD,GAAI,WAAW;AAAA,MACf,GAAG;AAAA,IACP;AAAA,EACJ;AACJ;","names":[]}
@@ -0,0 +1,29 @@
1
+ import "../chunk-J5LGTIGS.mjs";
2
+
3
+ // src/nextjs/withFeatureFlags.ts
4
+ function toUpperSnakeCase(key) {
5
+ return key.replace(/([A-Z])/g, "_$1").toUpperCase();
6
+ }
7
+ function withFeatureFlags(flagConfigs, nextConfig = {}) {
8
+ const stage = process.env.NEXT_PUBLIC_SST_STAGE ?? (process.env.NODE_ENV === "production" ? "production" : "development");
9
+ const defaultFlags = flagConfigs.default ?? {};
10
+ const stageOverrides = flagConfigs[stage] ?? {};
11
+ const resolvedFlags = { ...defaultFlags, ...stageOverrides };
12
+ const env = {};
13
+ for (const [key, value] of Object.entries(resolvedFlags)) {
14
+ const envKey = `NEXT_PUBLIC_FEATURE_FLAG_${toUpperSnakeCase(key)}`;
15
+ env[envKey] = String(value);
16
+ process.env[envKey] = String(value);
17
+ }
18
+ return {
19
+ ...nextConfig,
20
+ env: {
21
+ ...nextConfig.env,
22
+ ...env
23
+ }
24
+ };
25
+ }
26
+ export {
27
+ withFeatureFlags
28
+ };
29
+ //# sourceMappingURL=withFeatureFlags.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/nextjs/withFeatureFlags.ts"],"sourcesContent":["/**\n * Next.js config helper that injects feature flags as NEXT_PUBLIC_ environment variables.\n *\n * This allows client components to read feature flags via `getClientFeatureFlag()`\n * from `@smooai/config/feature-flags` without importing any Node.js-dependent code.\n *\n * @example\n * ```ts\n * // next.config.ts\n * import { withFeatureFlags } from '@smooai/config/nextjs/withFeatureFlags';\n * import defaultConfig from './.smooai-config/default';\n * import developmentConfig from './.smooai-config/development';\n *\n * const nextConfig = withFeatureFlags({\n * default: defaultConfig,\n * development: developmentConfig,\n * });\n *\n * export default nextConfig;\n * ```\n *\n * This will set environment variables like:\n * - NEXT_PUBLIC_FEATURE_FLAG_ABOUT_PAGE=true (in development)\n * - NEXT_PUBLIC_FEATURE_FLAG_ABOUT_PAGE=false (in production)\n *\n * Then in any client component:\n * ```tsx\n * import { getClientFeatureFlag } from '@smooai/config/feature-flags';\n * const isEnabled = getClientFeatureFlag('aboutPage');\n * ```\n */\n\ntype NextConfig = Record<string, unknown>;\ntype FeatureFlagConfig = Record<string, boolean>;\n\ninterface WithFeatureFlagsOptions {\n /** Default feature flag values (used in production). */\n default: FeatureFlagConfig;\n /** Development overrides (merged with default). */\n development?: FeatureFlagConfig;\n /** Additional stage-specific overrides. Key is the stage name. */\n [stage: string]: FeatureFlagConfig | undefined;\n}\n\n/**\n * Convert a camelCase key to UPPER_SNAKE_CASE.\n * e.g., \"aboutPage\" → \"ABOUT_PAGE\"\n */\nfunction toUpperSnakeCase(key: string): string {\n return key.replace(/([A-Z])/g, '_$1').toUpperCase();\n}\n\n/**\n * Wraps a Next.js config to inject feature flags as NEXT_PUBLIC_ environment variables.\n *\n * Reads `NEXT_PUBLIC_SST_STAGE` (or `NODE_ENV`) to determine which config to use.\n * Falls back to development config if stage is not 'production'.\n */\nexport function withFeatureFlags(flagConfigs: WithFeatureFlagsOptions, nextConfig: NextConfig = {}): NextConfig {\n const stage = process.env.NEXT_PUBLIC_SST_STAGE ?? (process.env.NODE_ENV === 'production' ? 'production' : 'development');\n\n // Merge default with stage-specific overrides\n const defaultFlags = flagConfigs.default ?? {};\n const stageOverrides = flagConfigs[stage] ?? {};\n const resolvedFlags: FeatureFlagConfig = { ...defaultFlags, ...stageOverrides };\n\n // Inject as NEXT_PUBLIC_ env vars\n const env: Record<string, string> = {};\n for (const [key, value] of Object.entries(resolvedFlags)) {\n const envKey = `NEXT_PUBLIC_FEATURE_FLAG_${toUpperSnakeCase(key)}`;\n env[envKey] = String(value);\n // Also set in process.env for SSR\n process.env[envKey] = String(value);\n }\n\n return {\n ...nextConfig,\n env: {\n ...(nextConfig.env as Record<string, string> | undefined),\n ...env,\n },\n };\n}\n"],"mappings":";;;AAgDA,SAAS,iBAAiB,KAAqB;AAC3C,SAAO,IAAI,QAAQ,YAAY,KAAK,EAAE,YAAY;AACtD;AAQO,SAAS,iBAAiB,aAAsC,aAAyB,CAAC,GAAe;AAC5G,QAAM,QAAQ,QAAQ,IAAI,0BAA0B,QAAQ,IAAI,aAAa,eAAe,eAAe;AAG3G,QAAM,eAAe,YAAY,WAAW,CAAC;AAC7C,QAAM,iBAAiB,YAAY,KAAK,KAAK,CAAC;AAC9C,QAAM,gBAAmC,EAAE,GAAG,cAAc,GAAG,eAAe;AAG9E,QAAM,MAA8B,CAAC;AACrC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,aAAa,GAAG;AACtD,UAAM,SAAS,4BAA4B,iBAAiB,GAAG,CAAC;AAChE,QAAI,MAAM,IAAI,OAAO,KAAK;AAE1B,YAAQ,IAAI,MAAM,IAAI,OAAO,KAAK;AAAA,EACtC;AAEA,SAAO;AAAA,IACH,GAAG;AAAA,IACH,KAAK;AAAA,MACD,GAAI,WAAW;AAAA,MACf,GAAG;AAAA,IACP;AAAA,EACJ;AACJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smooai/config",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Type-safe multi-language configuration management with schema validation, three-tier config (public, secret, feature flags), and runtime client support for TypeScript, Python, Rust, and Go.",
5
5
  "homepage": "https://github.com/SmooAI/config#readme",
6
6
  "bugs": {
@@ -72,6 +72,11 @@
72
72
  "import": "./dist/nextjs/getConfig.mjs",
73
73
  "require": "./dist/nextjs/getConfig.js"
74
74
  },
75
+ "./nextjs/withFeatureFlags": {
76
+ "types": "./dist/nextjs/withFeatureFlags.d.ts",
77
+ "import": "./dist/nextjs/withFeatureFlags.mjs",
78
+ "require": "./dist/nextjs/withFeatureFlags.js"
79
+ },
75
80
  "./feature-flags": {
76
81
  "types": "./dist/feature-flags/index.d.ts",
77
82
  "browser": {