@configdirector/nextjs-sdk 1.7.0 → 1.8.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.
Files changed (50) hide show
  1. package/README.md +41 -0
  2. package/dist/client/index.cjs +1 -5
  3. package/dist/client/index.d.cts +52 -216
  4. package/dist/client/index.d.cts.map +1 -1
  5. package/dist/client/index.d.mts +52 -216
  6. package/dist/client/index.d.mts.map +1 -1
  7. package/dist/client/index.mjs +1 -5
  8. package/dist/client/index.mjs.map +1 -1
  9. package/dist/client/installedTestClient-CrHwnJTr.mjs +7 -0
  10. package/dist/client/installedTestClient-CrHwnJTr.mjs.map +1 -0
  11. package/dist/client/installedTestClient-LbS5fHdP.cjs +6 -0
  12. package/dist/client/testing.cjs +2 -0
  13. package/dist/client/testing.d.cts +159 -0
  14. package/dist/client/testing.d.cts.map +1 -0
  15. package/dist/client/testing.d.mts +159 -0
  16. package/dist/client/testing.d.mts.map +1 -0
  17. package/dist/client/testing.mjs +3 -0
  18. package/dist/client/testing.mjs.map +1 -0
  19. package/dist/client/types-DA2VZKNX.d.mts +220 -0
  20. package/dist/client/types-DA2VZKNX.d.mts.map +1 -0
  21. package/dist/client/types-fL7X5zwg.d.cts +220 -0
  22. package/dist/client/types-fL7X5zwg.d.cts.map +1 -0
  23. package/dist/server/DefaultConfigDirectorClient-BhyVJv6Z.mjs +6 -0
  24. package/dist/server/DefaultConfigDirectorClient-BhyVJv6Z.mjs.map +1 -0
  25. package/dist/server/DefaultConfigDirectorClient-BngKzHat.cjs +5 -0
  26. package/dist/server/{errors-B1AJJTZ-.mjs → errors-BGpFuqOO.mjs} +1 -1
  27. package/dist/server/{errors-B1AJJTZ-.mjs.map → errors-BGpFuqOO.mjs.map} +1 -1
  28. package/dist/server/index.cjs +1 -1
  29. package/dist/server/index.d.cts +14 -288
  30. package/dist/server/index.d.cts.map +1 -1
  31. package/dist/server/index.d.mts +14 -288
  32. package/dist/server/index.d.mts.map +1 -1
  33. package/dist/server/index.mjs +1 -1
  34. package/dist/server/index.mjs.map +1 -1
  35. package/dist/server/testing.cjs +1 -0
  36. package/dist/server/testing.d.cts +119 -0
  37. package/dist/server/testing.d.cts.map +1 -0
  38. package/dist/server/testing.d.mts +119 -0
  39. package/dist/server/testing.d.mts.map +1 -0
  40. package/dist/server/testing.mjs +2 -0
  41. package/dist/server/testing.mjs.map +1 -0
  42. package/dist/server/types-DnzM2ukj.d.cts +292 -0
  43. package/dist/server/types-DnzM2ukj.d.cts.map +1 -0
  44. package/dist/server/types-qIeNbtNf.d.mts +292 -0
  45. package/dist/server/types-qIeNbtNf.d.mts.map +1 -0
  46. package/package.json +37 -2
  47. package/dist/server/DefaultConfigDirectorClient-C3kQeXox.cjs +0 -5
  48. package/dist/server/DefaultConfigDirectorClient-D7A_CT1K.mjs +0 -6
  49. package/dist/server/DefaultConfigDirectorClient-D7A_CT1K.mjs.map +0 -1
  50. /package/dist/server/{errors-zhcEWVnY.cjs → errors-CCbuIqT8.cjs} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../../shared/src/types.ts","../../../js-server-sdk/src/types.ts","../../src/server/singleton.ts","../../src/server/ssr.ts","../../../js-client-core/src/types.ts","../../../shared/src/logger.ts","../../src/client/types.ts","../../src/server/ConfigDirectorProvider.tsx","../../src/server/logger.ts"],"mappings":";;;;cAAa,cAAA;AAAA,KAUD,UAAA,WAAqB,cAAA;AAAA,KAErB,kBAAA;EAAA,CAAwB,GAAA;AAAA;AAAA,KAExB,eAAA,wCAAuD,kBAAA;AAAA,KAEvD,WAAA;EACV,EAAA;EACA,GAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,OAAA;AAAA;AAAA,KAQU,0BAAA;AAAA,UAEK,oBAAA;EACf,KAAA,CAAM,OAAA,aAAoB,IAAA;EAE1B,IAAA,CAAK,OAAA,aAAoB,IAAA;EAEzB,IAAA,CAAK,OAAA,aAAoB,IAAA;EAEzB,KAAA,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jC;EMaE,MAAA;EACA,OAAA;EACA,UAAA;ENf6C;AAE/C;;EMiBE,GAAA;ENjBiE;;AAEnE;EMmBE,OAAA;;;;EAIA,OAAA,GAAU,qBAAA;ENpBV;;;EMwBA,QAAA,GAAW,0BAAA;EAEX,KAAA,GAAQ,WAAA;ENxBD;AAQT;;;;;AAEA;;;;EMyBE,cAAA,GAAiB,MAAA,SAAe,WAAA;AAAA;;;;;ANxDlC;;KOUY,2BAAA,GAA8B,IAAA,CAAK,6BAAA;EPDrC;;AACV;;;EOME,UAAA;AAAA;APJF;;;;;AAEA;;;;;AAEA;;;;;;;;;;;;AAaA;;;;;AAEA;;;;;;;;;;;;;;;;;;AAUA;;;;;AAIA;;;;;AAUA;;AA3CA,iBOgEsB,sBAAA,CAAA;EACpB,QAAA;EACA,UAAA;EAAA,GACG;AAAA,GACF,iBAAA,CAAkB,2BAAA,IAA4B,OAAA,CAAA,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cChEpC,mBAAA,GACX,KAAA,EAAO,0BAAA,EACP,gBAAA,GAAmB,iCAAA,KAAiC,oBAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/server/singleton.ts","../../src/server/ssr.ts","../../../js-client-core/src/types.ts","../../../shared/src/logger.ts","../../src/client/types.ts","../../src/server/ConfigDirectorProvider.tsx","../../src/server/logger.ts"],"mappings":";;;;;QAIQ,MAAA;EAAA,IACF,4BAAA,EAA8B,oBAAA;EAAA,IAC9B,uBAAA;IAA2B,OAAA;IAAkB,UAAA;EAAA;AAAA;AAAA,KAGvC,eAAA;EALJ;;;;EAUN,YAAA;AAAA,IACE,2BAAA;;;;AANJ;;;;;AAoBA;;;;iBAAsB,QAAA,CAAS,OAAA,EAAS,eAAA,GAAkB,OAAA;AAAA,iBA6B1C,UAAA,CAAA;EAAgB,OAAA;EAAkB,UAAA;AAAA;AAAA,iBAIlC,eAAA,CAAA,GAAmB,oBAAA;;;KCxDvB,2BAAA;oDAEV,OAAA,GAAU,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A;EJgBO;;;;;EIVd,eAAA;EJc6B;;;EIV7B,OAAA,GAAU,qBAAA;;;;EAIV,QAAA,GAAW,0BAAA;EAEX,KAAA,GAAQ,WAAA;;;;;;;;AHhCV;;;EG2CE,cAAA,GAAiB,MAAA,SAAe,WAAA;AAAA;;;;;;AJrE4D;KKUlF,2BAAA,GAA8B,IAAA,CAAK,6BAAA;;;;;;EAM7C,UAAA;AAAA;;;;;ALPF;;;;;AAoBA;;;;;;;;;AA6BA;;;;;AAIA;;;;;;;;ACxDA;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;iBIkDsB,sBAAA,CAAA;EACpB,QAAA;EACA,UAAA;EAAA,GACG;AAAA,GACF,iBAAA,CAAkB,2BAAA,IAA4B,OAAA,CAAA,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cChEpC,mBAAA,GACX,KAAA,EAAO,0BAAA,EACP,gBAAA,GAAmB,iCAAA,KAAiC,oBAAA"}
@@ -1,294 +1,7 @@
1
+ import { a as ConfigDirectorLogger, c as ConfigEvaluation, d as ConnectionMode, i as ConfigDirectorLogMessageDecorator, l as ConfigState, n as ConfigDirectorClientOptions, o as ConfigDirectorLoggingLevel, r as ConfigDirectorContext, s as ConfigDirectorMetaContext, t as ConfigDirectorClient, u as ConfigValueType } from "./types-qIeNbtNf.mjs";
1
2
  import * as _$react_jsx_runtime0 from "react/jsx-runtime";
2
3
  import { PropsWithChildren } from "react";
3
4
 
4
- //#region ../shared/src/types.d.ts
5
- declare const ConfigTypeList: readonly ["custom", "boolean", "string", "integer", "float", "enum", "url", "json"];
6
- type ConfigType = (typeof ConfigTypeList)[number];
7
- type ConfigEnumLikeType = {
8
- [key: string]: string | number;
9
- };
10
- type ConfigValueType = string | number | boolean | object | ConfigEnumLikeType;
11
- type ConfigState = {
12
- id: string;
13
- key: string;
14
- type: ConfigType;
15
- value: string | undefined | null;
16
- valueId?: string | undefined | null;
17
- };
18
- type ConfigDirectorLoggingLevel = "debug" | "info" | "warn" | "error" | "off";
19
- interface ConfigDirectorLogger {
20
- debug(message: string, ...args: any): void;
21
- info(message: string, ...args: any): void;
22
- warn(message: string, ...args: any): void;
23
- error(message: string, ...args: any): void;
24
- }
25
- interface ConfigDirectorLogMessageDecorator {
26
- decorateMessage(message: string): string;
27
- }
28
- type EvaluationReason = "found-match" | "config-state-missing" | "client-not-ready" | "type-mismatch" | "value-missing" | "invalid-number" | "invalid-json" | "invalid-boolean";
29
- type ConfigEvaluation = {
30
- key: string;
31
- value: ConfigValueType;
32
- valueId?: string;
33
- isDefaultValue: boolean;
34
- reason: EvaluationReason;
35
- context?: ConfigDirectorContext;
36
- };
37
- /**
38
- * The user's context to be sent to ConfigDirector. This context will be used for targeting
39
- * rules evaluation.
40
- */
41
- type ConfigDirectorContext = {
42
- /**
43
- * The user's identifier. This should be a value that uniquely identifies an application
44
- * user.
45
- * In the case of anonymous users, you could generate a UUID or alternatively not provide
46
- * the {@link id} and the SDK will generate a random UUID. However, keep in mind that this
47
- * value is used for segmenting users in percentage rollouts, and changes to the {@link id}
48
- * could result in the user being assigned to a different percentile.
49
- */
50
- id?: string;
51
- /**
52
- * The user's display name. This will be shown in the ConfigDirector dashboard and may be
53
- * used for targeting rules.
54
- */
55
- name?: string;
56
- /**
57
- * Any arbitrary traits for the current user. They will be shown in the ConfigDirector
58
- * dashboard and may be used for targeting rules.
59
- */
60
- traits?: {
61
- [key: string]: unknown;
62
- };
63
- /**
64
- * Whether or not to treat the context as anonymous during evaluation. When `true`, the
65
- * context values will be used for targeting rules evaluation but the context will not be
66
- * persisted and will not appear in the dashboard.
67
- *
68
- * @default false
69
- */
70
- anonymous?: boolean;
71
- };
72
- /**
73
- * Metadata about your application. It is recommended you include these values when configuring
74
- * a ConfigDirector client so that you can use them in targeting rules.
75
- */
76
- type ConfigDirectorMetaContext = {
77
- appVersion?: string;
78
- appName?: string;
79
- };
80
- type ConnectionMode = "streaming" | "polling";
81
- //#endregion
82
- //#region ../js-server-sdk/src/types.d.ts
83
- /**
84
- * Configuration options for the {@link ConfigDirectorClient}
85
- */
86
- type ConfigDirectorClientOptions = {
87
- /**
88
- * Application metadata that remains constant through the lifetime of the connection
89
- */
90
- metadata?: ConfigDirectorMetaContext;
91
- /**
92
- * Connection options
93
- */
94
- connection?: {
95
- /**
96
- * The connection mode to be used, one of `streaming` (default) or `polling`.
97
- * If set to `streaming`, the connection will remain open and receive updates whenever
98
- * config state is updated on the ConfigDirector dashboard.
99
- * When set to `polling`, there will be an initial request to retrieve config state during
100
- * initialization, and additional requests on a `pollingInterval`.
101
- *
102
- * Defaults to `streaming`
103
- */
104
- mode?: ConnectionMode;
105
- /**
106
- * The polling interval in _seconds_ when the `mode` is set to `polling`. This option has no
107
- * effect when the `mode` is set to `streaming`.
108
- *
109
- * Defaults to 60 seconds
110
- */
111
- pollingInterval?: number;
112
- /**
113
- * The timeout, in milliseconds, to be used in initialization and when updating the context.
114
- * If streaming is enabled, the operation (initialization or context update) may still succeed
115
- * after it times out if no unrecoverable errors are encountered (like an invalid SDK key).
116
- * If streaming is disabled, if the operation times out, it will not be retried.
117
- *
118
- * Defaults to 3,000 milliseconds (3 seconds)
119
- */
120
- timeout?: number;
121
- /**
122
- * The base URL to the ConfigDirector SDK server. To be used only when needing to route through a
123
- * proxy to connect to the ConfigDirector SDK server. Please refer to the docs on how to configure
124
- * a proxy for the client SDK.
125
- */
126
- url?: string;
127
- };
128
- /**
129
- * A logger that implements {@link ConfigDirectorLogger}. It defaults to the ConfigDirector console
130
- * logger set to 'warn' level.
131
- *
132
- * The log level of the default logger can be adjusted by creating a default logger with the desired
133
- * level and providing it in this property:
134
- * @example
135
- * import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
136
- * const client = createClient(
137
- * "YOUR-SERVER-SDK-KEY",
138
- * { logger: createConsoleLogger("debug") },
139
- * );
140
- */
141
- logger?: ConfigDirectorLogger;
142
- /**
143
- * Telemetry tunning. It is unlikely these settings need to be adjusted. However, in cases where
144
- * your application has a large number of evaluations per second, you can adjust these settings
145
- * to tune the memory footprint and frequency of telemetry requests.
146
- * Keep in mind that ConfigDirector relies on these telemetry events to provide insights and features
147
- * related to the configs being used.
148
- */
149
- telemetry?: {
150
- /**
151
- * The size limit of telemetry event queues. If the size limit is reached before the events are
152
- * flushed to the network, older events will be dropped.
153
- *
154
- * ConfigDirector keeps a count of dropped events. If the number of dropped events is higher than
155
- * 50% of the total events, ConfigDirector will issue a notification alert in the dashboard.
156
- *
157
- * A number between 100 and 100,000. Defaults to 5,000.
158
- */
159
- eventQueueLimit?: number;
160
- /**
161
- * How often events are flushed and sent over the network in milliseconds.
162
- *
163
- * Decrease this number if your application consistently captures a large number of events in short
164
- * periods of time in order to reduce memory footprint from a large event queue.
165
- *
166
- * Defaults to 30,000 milliseconds (30 seconds)
167
- */
168
- flushInterval?: number;
169
- };
170
- /**
171
- * Handlers for hooks/events emitted by the client. Each hook accepts either a single event handler or
172
- * an array of event handlers.
173
- *
174
- * @example
175
- * import { createClient, createConsoleLogger } from "@configdirector/server-sdk";
176
- * const client = createClient(
177
- * "YOUR-SERVER-SDK-KEY",
178
- * {
179
- * hooks: {
180
- * configEvaluated: (event) => { console.log(event.evaluation); }
181
- * },
182
- * },
183
- * );
184
- */
185
- hooks?: ClientHooks$1;
186
- };
187
- type ClientEvents$1 = {
188
- configsUpdated: {
189
- keys: string[];
190
- };
191
- clientReady: undefined;
192
- configEvaluated: {
193
- evaluation: ConfigEvaluation;
194
- };
195
- connectionError: {
196
- error: Error;
197
- };
198
- };
199
- type ClientHooks$1 = {
200
- clientReady?: HookHandler$1<"clientReady"> | HookHandler$1<"clientReady">[];
201
- configsUpdated?: HookHandler$1<"configsUpdated"> | HookHandler$1<"configsUpdated">[];
202
- configEvaluated?: HookHandler$1<"configEvaluated"> | HookHandler$1<"configEvaluated">[];
203
- connectionError?: HookHandler$1<"connectionError"> | HookHandler$1<"connectionError">[];
204
- };
205
- type HookHandler$1<TEvent extends keyof ClientEvents$1> = (payload: ClientEvents$1[TEvent]) => void;
206
- type WatchHandler<T extends ConfigValueType> = (message: T) => void;
207
- /**
208
- * The ConfigDirector SDK client object.
209
- *
210
- * Applications should create a single instance of `ConfigDirectorClient`, and call
211
- * {@link initialize} during application initialization.
212
- */
213
- interface ConfigDirectorClient {
214
- /**
215
- * Initializes the connection to ConfigDirector to retrieve config definitions. Until
216
- * initialization is successful, all flags will return their default value provided to
217
- * {@link watch} or {@link getValue}.
218
- *
219
- * If the connection fails or is interrupted with a transient error (network error,
220
- * internal server error, etc) the client will continue to attempt to connect. However,
221
- * if the connection fails with a persistent error, like an invalid SDK key, the client will
222
- * not attempt to re-connect and an error will be logged to the console or the provided
223
- * logger.
224
- */
225
- initialize(): Promise<void>;
226
- /**
227
- * Returns whether or not the client is ready after calling {@link initialize}
228
- *
229
- * The definition of ready is that the connection to the server was successful, and config definitions
230
- * were received.
231
- */
232
- get isReady(): boolean;
233
- /**
234
- * Evaluates a config and returns its value based on the current context and targeting rules
235
- *
236
- * @returns The evaluated config value, or the `defaultValue` if the config state was unavailable
237
- * @param configKey The config key to evaluate
238
- * @param defaultValue The default value to be returned if the config state is unavailable. For
239
- * example, if the client cannot connect to the server due to network conditions, or if getValue
240
- * is called before initialization is done.
241
- * @param context The user's context to be used for targeting rules evaluation (optional)
242
- */
243
- getValue<T extends ConfigValueType>(configKey: string, defaultValue: T, context?: ConfigDirectorContext): T;
244
- /**
245
- * Watches for changes to a a config evaluation value. Whenever the config value changes, the
246
- * provided callback function will be called with the new value. Changes can happen due to updates
247
- * to the config in the ConfigDirector dashboard, or if the context is updated via {@link updateContext}.
248
- *
249
- * @returns An 'unwatch' function that can be called to remove the subscriber
250
- *
251
- * @param configKey The config key to watch
252
- * @param defaultValue The default value to be referenced if the config state is unavailable
253
- * @param callback The callback function to be called whenever the config value is updated
254
- * @param context The user's context to be used for targeting rules evaluation (optional)
255
- */
256
- watch<T extends ConfigValueType>(configKey: string, defaultValue: T, callback: WatchHandler<T>, context?: ConfigDirectorContext): () => void;
257
- /**
258
- * Removes a particular subscriber to the given `configKey`, or all subscribers if no callback
259
- * is provided.
260
- *
261
- * @param configKey The config key to remove subscribers from
262
- * @param callback The subscriber to be removed. If not provided, all subscribers are removed for
263
- * the given `configKey`.
264
- */
265
- unwatch<T extends ConfigValueType>(configKey: string, callback?: WatchHandler<T>): void;
266
- /**
267
- * Removes all subscribers from all config keys
268
- */
269
- unwatchAll(): void;
270
- /**
271
- * Returns the evaluated {@link ConfigState} for every known config key, or only the keys
272
- * listed in `configKeys` when provided.
273
- *
274
- * Intended for SSR hydration — does NOT record telemetry events. Returns an empty object
275
- * when the client is not yet ready.
276
- */
277
- getAllConfigs(options?: {
278
- context?: ConfigDirectorContext;
279
- configKeys?: string[];
280
- }): Record<string, ConfigState>;
281
- on<T extends keyof ClientEvents$1>(eventName: T, handler: (args: ClientEvents$1[T]) => void): void;
282
- off<T extends keyof ClientEvents$1>(eventName: T, handler?: (args: ClientEvents$1[T]) => void): void;
283
- /**
284
- * Disposes of the client. All connections are closed, and all event and config key subscribers
285
- * are removed.
286
- *
287
- * Intended to be called when your application shuts down
288
- */
289
- dispose(): void;
290
- }
291
- //#endregion
292
5
  //#region src/server/singleton.d.ts
293
6
  declare global {
294
7
  var __configDirectorServerClient: ConfigDirectorClient | undefined;
@@ -357,6 +70,7 @@ type HookHandler<TEvent extends keyof ClientEvents> = (payload: ClientEvents[TEv
357
70
  type ClientEvents = {
358
71
  configsUpdated: {
359
72
  keys: string[];
73
+ removedKeys: string[];
360
74
  };
361
75
  clientReady: {
362
76
  action: ClientConnectAction;
@@ -401,6 +115,18 @@ type ConfigDirectorProviderOptions = {
401
115
  * Initialization timeout in milliseconds. Defaults to 3000.
402
116
  */
403
117
  timeout?: number;
118
+ /**
119
+ * The connection mode, one of `streaming` or `polling`. In `streaming` mode the connection stays
120
+ * open and receives config updates as they happen. In `polling` mode configs are fetched once during
121
+ * initialization and then again on every `pollingInterval`. Defaults to `streaming`.
122
+ */
123
+ mode?: ConnectionMode;
124
+ /**
125
+ * The polling interval in seconds when `mode` is `polling`. Has no effect in `streaming` mode.
126
+ * Defaults to 60 seconds. A value below the minimum of 30 seconds is raised to 30 seconds and a
127
+ * warning is logged.
128
+ */
129
+ pollingInterval?: number;
404
130
  /**
405
131
  * Initial user context to evaluate targeting rules against.
406
132
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../shared/src/types.ts","../../../js-server-sdk/src/types.ts","../../src/server/singleton.ts","../../src/server/ssr.ts","../../../js-client-core/src/types.ts","../../../shared/src/logger.ts","../../src/client/types.ts","../../src/server/ConfigDirectorProvider.tsx","../../src/server/logger.ts"],"mappings":";;;;cAAa,cAAA;AAAA,KAUD,UAAA,WAAqB,cAAA;AAAA,KAErB,kBAAA;EAAA,CAAwB,GAAA;AAAA;AAAA,KAExB,eAAA,wCAAuD,kBAAA;AAAA,KAEvD,WAAA;EACV,EAAA;EACA,GAAA;EACA,IAAA,EAAM,UAAA;EACN,KAAA;EACA,OAAA;AAAA;AAAA,KAQU,0BAAA;AAAA,UAEK,oBAAA;EACf,KAAA,CAAM,OAAA,aAAoB,IAAA;EAE1B,IAAA,CAAK,OAAA,aAAoB,IAAA;EAEzB,IAAA,CAAK,OAAA,aAAoB,IAAA;EAEzB,KAAA,CAAM,OAAA,aAAoB,IAAA;AAAA;AAAA,UAGX,iCAAA;EACf,eAAA,CAAgB,OAAA;AAAA;AAAA,KAGN,gBAAA;AAAA,KAUA,gBAAA;EACV,GAAA;EACA,KAAA,EAAO,eAAA;EACP,OAAA;EACA,cAAA;EACA,MAAA,EAAQ,gBAAA;EACR,OAAA,GAAU,qBAAA;AAAA;AAhCZ;;;;AAAA,KAsCY,qBAAA;EApCK;;;;;;;;EA6Cf,EAAA;EA1CyB;;;;EAgDzB,IAAA;EA5CM;;;;EAkDN,MAAA;IAAA,CAAY,GAAA;EAAA;EA9CZ;;AAGF;;;;;EAoDE,SAAA;AAAA;;;;;KAOU,yBAAA;EACV,UAAA;EACA,OAAA;AAAA;A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A3CA,iBOgEsB,sBAAA,CAAA;EACpB,QAAA;EACA,UAAA;EAAA,GACG;AAAA,GACF,iBAAA,CAAkB,2BAAA,IAA4B,OAAA,CAAA,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cChEpC,mBAAA,GACX,KAAA,EAAO,0BAAA,EACP,gBAAA,GAAmB,iCAAA,KAAiC,oBAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/server/singleton.ts","../../src/server/ssr.ts","../../../js-client-core/src/types.ts","../../../shared/src/logger.ts","../../src/client/types.ts","../../src/server/ConfigDirectorProvider.tsx","../../src/server/logger.ts"],"mappings":";;;;;QAIQ,MAAA;EAAA,IACF,4BAAA,EAA8B,oBAAA;EAAA,IAC9B,uBAAA;IAA2B,OAAA;IAAkB,UAAA;EAAA;AAAA;AAAA,KAGvC,eAAA;EALJ;;;;EAUN,YAAA;AAAA,IACE,2BAAA;;;;AANJ;;;;;AAoBA;;;;iBAAsB,QAAA,CAAS,OAAA,EAAS,eAAA,GAAkB,OAAA;AAAA,iBA6B1C,UAAA,CAAA;EAAgB,OAAA;EAAkB,UAAA;AAAA;AAAA,iBAIlC,eAAA,CAAA,GAAmB,oBAAA;;;KCxDvB,2BAAA;oDAEV,OAAA,GAAU,qBAAA;;ADRkF;;;ECa5F,UAAA;AAAA;;;;;;;;;ADJF;;iBCiBgB,oBAAA,CAAqB,OAAA,GAAU,2BAAA,GAA8B,MAAA,SAAe,WAAA;;;KC0FhF,WAAA;EACV,WAAA,GAAc,WAAA,kBAA6B,WAAA;EAC3C,cAAA,GAAiB,WAAA,qBAAgC,WAAA;EACjD,cAAA,GAAiB,WAAA,qBAAgC,WAAA;EACjD,eAAA,GAAkB,WAAA,sBAAiC,WAAA;EACnD,eAAA,GAAkB,WAAA,sBAAiC,WAAA;AAAA;AAAA,KAGzC,mBAAA;AAAA,KAEA,WAAA,sBAAiC,YAAA,KAAiB,OAAA,EAAS,YAAA,CAAa,MAAA;AAAA,KAExE,YAAA;E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AA4B,OAAA,CAAA,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cChEpC,mBAAA,GACX,KAAA,EAAO,0BAAA,EACP,gBAAA,GAAmB,iCAAA,KAAiC,oBAAA"}
@@ -1,2 +1,2 @@
1
- import{i as e,n as t}from"./errors-B1AJJTZ-.mjs";import{ConfigDirectorProvider as n}from"@configdirector/nextjs-sdk/client";import{jsx as r}from"react/jsx-runtime";var i=class{decorateMessage(e){return`[ConfigDirector:nextjs-sdk] ${e}`}};const a=(t,n)=>new e(t??`warn`,n??new i),o=(t,n)=>new e(t,n??new i);async function s(e){if(process.env.NEXT_RUNTIME===`nodejs`){if(!e.serverSdkKey){let e=`The ConfigDirector serverSdkKey must be provided to register(). You can pass it via process.env.CONFIGDIRECTOR_SERVER_KEY.`;throw a().error(e),new t(e)}if(!globalThis.__configDirectorServerClient){let{DefaultConfigDirectorClient:t}=await import(`./DefaultConfigDirectorClient-D7A_CT1K.mjs`),{serverSdkKey:n,...r}=e;globalThis.__configDirectorAppMeta={appName:e.metadata?.appName,appVersion:e.metadata?.appVersion};let i=new t(n,{sdkName:`nextjs-sdk`,sdkVersion:`1.7.0`},r);globalThis.__configDirectorServerClient=i,await i.initialize()}}}function c(){return globalThis.__configDirectorAppMeta??{}}function l(){if(!globalThis.__configDirectorServerClient)throw new t(`[ConfigDirector] Server client not initialized. Make sure to call register() in your instrumentation.ts file before using the SDK.`);return globalThis.__configDirectorServerClient}const u=a();function d(e){try{return l().getAllConfigs(e)}catch(e){return u.error(`Error retrieving SSR config set:`,e),{}}}async function f({children:e,configKeys:t,...i}){let a=d({context:i.context,configKeys:t}),o=c();return r(n,{...i,appName:i.appName??o.appName,appVersion:i.appVersion??o.appVersion,initialConfigs:a,children:e})}export{f as ConfigDirectorProvider,o as createConsoleLogger,d as generateSsrConfigSet,c as getAppMeta,l as getConfigClient,s as register};
1
+ import{i as e,n as t}from"./errors-BGpFuqOO.mjs";import{ConfigDirectorProvider as n}from"@configdirector/nextjs-sdk/client";import{jsx as r}from"react/jsx-runtime";var i=class{decorateMessage(e){return`[ConfigDirector:nextjs-sdk] ${e}`}};const a=(t,n)=>new e(t??`warn`,n??new i),o=(t,n)=>new e(t,n??new i);async function s(e){if(process.env.NEXT_RUNTIME===`nodejs`){if(!e.serverSdkKey){let e=`The ConfigDirector serverSdkKey must be provided to register(). You can pass it via process.env.CONFIGDIRECTOR_SERVER_KEY.`;throw a().error(e),new t(e)}if(!globalThis.__configDirectorServerClient){let{DefaultConfigDirectorClient:t}=await import(`./DefaultConfigDirectorClient-BhyVJv6Z.mjs`).then(e=>e.n),{serverSdkKey:n,...r}=e;globalThis.__configDirectorAppMeta={appName:e.metadata?.appName,appVersion:e.metadata?.appVersion};let i=new t(n,{sdkName:`nextjs-sdk`,sdkVersion:`1.8.0`},r);globalThis.__configDirectorServerClient=i,await i.initialize()}}}function c(){return globalThis.__configDirectorAppMeta??{}}function l(){if(!globalThis.__configDirectorServerClient)throw new t(`[ConfigDirector] Server client not initialized. Make sure to call register() in your instrumentation.ts file before using the SDK.`);return globalThis.__configDirectorServerClient}const u=a();function d(e){try{return l().getAllConfigs(e)}catch(e){return u.error(`Error retrieving SSR config set:`,e),{}}}async function f({children:e,configKeys:t,...i}){let a=d({context:i.context,configKeys:t}),o=c();return r(n,{...i,appName:i.appName??o.appName,appVersion:i.appVersion??o.appVersion,initialConfigs:a,children:e})}export{f as ConfigDirectorProvider,o as createConsoleLogger,d as generateSsrConfigSet,c as getAppMeta,l as getConfigClient,s as register};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["ClientProvider"],"sources":["../../src/server/logger.ts","../../src/server/singleton.ts","../../src/server/ssr.ts","../../src/server/ConfigDirectorProvider.tsx"],"sourcesContent":["import { DefaultConsoleLogger } from \"@shared/logger\";\nimport type { ConfigDirectorLoggingLevel, ConfigDirectorLogMessageDecorator } from \"@shared/types\";\n\nclass LogMessageDecorator implements ConfigDirectorLogMessageDecorator {\n decorateMessage(message: string): string {\n return `[ConfigDirector:nextjs-sdk] ${message}`;\n }\n}\n\nexport const createDefaultLogger = (\n level?: ConfigDirectorLoggingLevel,\n messageDecorator?: ConfigDirectorLogMessageDecorator,\n) => {\n return new DefaultConsoleLogger(level ?? \"warn\", messageDecorator ?? new LogMessageDecorator());\n};\n\nexport const createConsoleLogger = (\n level: ConfigDirectorLoggingLevel,\n messageDecorator?: ConfigDirectorLogMessageDecorator,\n) => {\n return new DefaultConsoleLogger(level, messageDecorator ?? new LogMessageDecorator());\n};\n","import type { ConfigDirectorClient, ConfigDirectorClientOptions } from \"@js-server-sdk/types\";\nimport { createDefaultLogger } from \"./logger\";\nimport { ConfigDirectorInitializationError } from \"@shared/errors\";\n\ndeclare global {\n var __configDirectorServerClient: ConfigDirectorClient | undefined;\n var __configDirectorAppMeta: { appName?: string; appVersion?: string } | undefined;\n}\n\nexport type RegisterOptions = {\n /**\n * Your ConfigDirector Server SDK key. This is a secret value — do not commit it to source\n * control. Provide it via an environment variable (e.g. process.env.CONFIGDIRECTOR_SERVER_KEY).\n */\n serverSdkKey: string;\n} & ConfigDirectorClientOptions;\n\n/**\n * Initializes the ConfigDirector server SDK singleton. Call this from your Next.js\n * `instrumentation.ts` file so it runs once when the server starts:\n *\n * ```ts\n * // instrumentation.ts\n * export async function register() {\n * const { register } = await import(\"@configdirector/nextjs-sdk/server\");\n * await register({ serverSdkKey: process.env.CONFIGDIRECTOR_SERVER_KEY! });\n * }\n * ```\n */\nexport async function register(options: RegisterOptions): Promise<void> {\n if (process.env[\"NEXT_RUNTIME\"] !== \"nodejs\") {\n return;\n }\n\n if (!options.serverSdkKey) {\n const message =\n \"The ConfigDirector serverSdkKey must be provided to register(). You can pass it via process.env.CONFIGDIRECTOR_SERVER_KEY.\";\n createDefaultLogger().error(message);\n throw new ConfigDirectorInitializationError(message);\n }\n\n if (!globalThis.__configDirectorServerClient) {\n const { DefaultConfigDirectorClient } = await import(\"@js-server-sdk/DefaultConfigDirectorClient\");\n const { serverSdkKey, ...clientOptions } = options;\n globalThis.__configDirectorAppMeta = {\n appName: options.metadata?.appName,\n appVersion: options.metadata?.appVersion,\n };\n const client = new DefaultConfigDirectorClient(\n serverSdkKey,\n { sdkName: \"nextjs-sdk\", sdkVersion: \"__VERSION__\" },\n clientOptions,\n );\n globalThis.__configDirectorServerClient = client;\n await client.initialize();\n }\n}\n\nexport function getAppMeta(): { appName?: string; appVersion?: string } {\n return globalThis.__configDirectorAppMeta ?? {};\n}\n\nexport function getConfigClient(): ConfigDirectorClient {\n if (!globalThis.__configDirectorServerClient) {\n throw new ConfigDirectorInitializationError(\n \"[ConfigDirector] Server client not initialized. Make sure to call register() in your instrumentation.ts file before using the SDK.\",\n );\n }\n return globalThis.__configDirectorServerClient;\n}\n","import type { ConfigDirectorContext, ConfigState } from \"@js-server-sdk/types\";\nimport { getConfigClient } from \"./singleton\";\nimport { createDefaultLogger } from \"./logger\";\n\nconst logger = createDefaultLogger();\n\nexport type GenerateSsrConfigSetOptions = {\n /** User context for targeting rule evaluation. */\n context?: ConfigDirectorContext;\n /**\n * Restrict the returned config set to these keys. When omitted, all known configs are\n * returned. Useful when you want to pre-evaluate only a specific subset of flags.\n */\n configKeys?: string[];\n};\n\n/**\n * Evaluates configs server-side and returns a map of {@link ConfigState} objects keyed by\n * config key, suitable for passing as `initialConfigs` to `ConfigDirectorProvider`.\n *\n * Returns an empty object when the server SDK isn't initialized yet (e.g. during\n * `next build` static analysis without a live connection).\n *\n * In most cases you don't need this directly — use the `ConfigDirectorProvider` exported\n * from `@configdirector/nextjs-sdk/server`, which calls this automatically.\n */\nexport function generateSsrConfigSet(options?: GenerateSsrConfigSetOptions): Record<string, ConfigState> {\n try {\n return getConfigClient().getAllConfigs(options);\n } catch (error) {\n logger.error(\"Error retrieving SSR config set:\", error);\n return {};\n }\n}\n","import type { PropsWithChildren } from \"react\";\nimport { ConfigDirectorProvider as ClientProvider } from \"@configdirector/nextjs-sdk/client\";\nimport type { ConfigDirectorProviderOptions } from \"../client/types\";\nimport { generateSsrConfigSet } from \"./ssr\";\nimport { getAppMeta } from \"./singleton\";\n\n/**\n * Props for {@link ConfigDirectorProvider}. Identical to the client provider options\n * except `initialConfigs` is omitted — SSR-evaluated values are injected automatically.\n */\nexport type ConfigDirectorProviderProps = Omit<ConfigDirectorProviderOptions, \"initialConfigs\"> & {\n /**\n * Restrict SSR pre-evaluation to these config keys. When omitted, all known configs are\n * pre-evaluated. Useful when you have a large config set and only need a subset hydrated\n * on this layout.\n */\n configKeys?: string[];\n};\n\n/**\n * React Server Component wrapper around the ConfigDirector client provider.\n *\n * Place this in your root layout. It pre-evaluates all configs on the server using the\n * provided context and passes them to the client provider, preventing any flash of wrong\n * content on hydration.\n *\n * Requires Next.js 13+ (App Router) and React 18+.\n *\n * Read `sdkKey` from a plain environment variable (e.g. `CONFIGDIRECTOR_CLIENT_KEY`), NOT one\n * prefixed with `NEXT_PUBLIC_` — even here, inside a Server Component. Next.js substitutes\n * `NEXT_PUBLIC_*` references with a literal string at compile time wherever they appear in\n * code it bundles, with no exemption for Server Components; that permanently freezes the\n * value into the build artifact the moment you reference it here, regardless of the two\n * deployment strategies below. A plain variable, by contrast, is read live from `process.env`\n * — its resolved value (not the variable lookup itself) is what gets passed as a prop to the\n * client provider below, which is how it safely reaches the browser without ever being baked\n * into the bundle as source.\n *\n * **Deploying one build artifact to multiple environments (e.g. one Docker image promoted\n * from staging to prod):** a plain variable is only read fresh per request if this component's\n * render actually re-runs on each request — otherwise Next.js still statically prerenders the\n * route once at build time and caches the output to a static HTML file, silently freezing\n * whichever value was set at build time. Make sure your root layout either reads a per-request\n * API like `cookies()` (as below, which forces dynamic rendering as a side effect) or adds\n * `export const dynamic = \"force-dynamic\";` if it doesn't otherwise need one. The trade-off is\n * that the route loses static generation/ISR caching, since it now renders on every request.\n *\n * **Building a separate artifact per environment:** if you'd rather keep static generation\n * (and are fine building once per environment, e.g. as a distinct step per env in CI), no\n * layout changes are needed — a plain environment variable set at build time is read once and\n * baked into the static output for that build, same as `NEXT_PUBLIC_` would be, just without\n * also exposing it to arbitrary client-side code that isn't a descendant of this provider.\n *\n * @example\n * ```tsx\n * // app/layout.tsx\n * import { ConfigDirectorProvider } from \"@configdirector/nextjs-sdk/server\";\n * import { cookies } from \"next/headers\";\n *\n * export default async function RootLayout({ children }) {\n * const userId = (await cookies()).get(\"userId\")?.value;\n * return (\n * <html>\n * <body>\n * <ConfigDirectorProvider\n * sdkKey={process.env.CONFIGDIRECTOR_CLIENT_KEY!}\n * context={{ userId }}\n * >\n * {children}\n * </ConfigDirectorProvider>\n * </body>\n * </html>\n * );\n * }\n * ```\n */\nexport async function ConfigDirectorProvider({\n children,\n configKeys,\n ...props\n}: PropsWithChildren<ConfigDirectorProviderProps>) {\n const initialConfigs = generateSsrConfigSet({ context: props.context, configKeys });\n const appMeta = getAppMeta();\n return (\n <ClientProvider\n {...props}\n appName={props.appName ?? appMeta.appName}\n appVersion={props.appVersion ?? appMeta.appVersion}\n initialConfigs={initialConfigs}>\n {children}\n </ClientProvider>\n );\n}\n"],"mappings":"oKAGA,IAAM,EAAN,KAAuE,CACrE,gBAAgB,EAAyB,CACvC,MAAO,+BAA+B,MAI1C,MAAa,GACX,EACA,IAEO,IAAI,EAAqB,GAAS,OAAQ,GAAoB,IAAI,EAAsB,CAGpF,GACX,EACA,IAEO,IAAI,EAAqB,EAAO,GAAoB,IAAI,EAAsB,CCSvF,eAAsB,EAAS,EAAyC,CAClE,WAAQ,IAAI,eAAoB,SAIpC,IAAI,CAAC,EAAQ,aAAc,CACzB,IAAM,EACJ,6HAEF,MADA,GAAqB,CAAC,MAAM,EAAQ,CAC9B,IAAI,EAAkC,EAAQ,CAGtD,GAAI,CAAC,WAAW,6BAA8B,CAC5C,GAAM,CAAE,+BAAgC,MAAM,OAAO,8CAC/C,CAAE,eAAc,GAAG,GAAkB,EAC3C,WAAW,wBAA0B,CACnC,QAAS,EAAQ,UAAU,QAC3B,WAAY,EAAQ,UAAU,WAC/B,CACD,IAAM,EAAS,IAAI,EACjB,EACA,CAAE,QAAS,aAAc,WAAY,QAAe,CACpD,EACD,CACD,WAAW,6BAA+B,EAC1C,MAAM,EAAO,YAAY,GAI7B,SAAgB,GAAwD,CACtE,OAAO,WAAW,yBAA2B,EAAE,CAGjD,SAAgB,GAAwC,CACtD,GAAI,CAAC,WAAW,6BACd,MAAM,IAAI,EACR,qIACD,CAEH,OAAO,WAAW,6BChEpB,MAAM,EAAS,GAAqB,CAsBpC,SAAgB,EAAqB,EAAoE,CACvG,GAAI,CACF,OAAO,GAAiB,CAAC,cAAc,EAAQ,OACxC,EAAO,CAEd,OADA,EAAO,MAAM,mCAAoC,EAAM,CAChD,EAAE,EC6Cb,eAAsB,EAAuB,CAC3C,WACA,aACA,GAAG,GAC8C,CACjD,IAAM,EAAiB,EAAqB,CAAE,QAAS,EAAM,QAAS,aAAY,CAAC,CAC7E,EAAU,GAAY,CAC5B,OACE,EAACA,EAAD,CACE,GAAI,EACJ,QAAS,EAAM,SAAW,EAAQ,QAClC,WAAY,EAAM,YAAc,EAAQ,WACxB,iBACf,WACc,CAAA"}
1
+ {"version":3,"file":"index.mjs","names":["ClientProvider"],"sources":["../../src/server/logger.ts","../../src/server/singleton.ts","../../src/server/ssr.ts","../../src/server/ConfigDirectorProvider.tsx"],"sourcesContent":["import { DefaultConsoleLogger } from \"@shared/logger\";\nimport type { ConfigDirectorLoggingLevel, ConfigDirectorLogMessageDecorator } from \"@shared/types\";\n\nclass LogMessageDecorator implements ConfigDirectorLogMessageDecorator {\n decorateMessage(message: string): string {\n return `[ConfigDirector:nextjs-sdk] ${message}`;\n }\n}\n\nexport const createDefaultLogger = (\n level?: ConfigDirectorLoggingLevel,\n messageDecorator?: ConfigDirectorLogMessageDecorator,\n) => {\n return new DefaultConsoleLogger(level ?? \"warn\", messageDecorator ?? new LogMessageDecorator());\n};\n\nexport const createConsoleLogger = (\n level: ConfigDirectorLoggingLevel,\n messageDecorator?: ConfigDirectorLogMessageDecorator,\n) => {\n return new DefaultConsoleLogger(level, messageDecorator ?? new LogMessageDecorator());\n};\n","import type { ConfigDirectorClient, ConfigDirectorClientOptions } from \"@js-server-sdk/types\";\nimport { createDefaultLogger } from \"./logger\";\nimport { ConfigDirectorInitializationError } from \"@shared/errors\";\n\ndeclare global {\n var __configDirectorServerClient: ConfigDirectorClient | undefined;\n var __configDirectorAppMeta: { appName?: string; appVersion?: string } | undefined;\n}\n\nexport type RegisterOptions = {\n /**\n * Your ConfigDirector Server SDK key. This is a secret value — do not commit it to source\n * control. Provide it via an environment variable (e.g. process.env.CONFIGDIRECTOR_SERVER_KEY).\n */\n serverSdkKey: string;\n} & ConfigDirectorClientOptions;\n\n/**\n * Initializes the ConfigDirector server SDK singleton. Call this from your Next.js\n * `instrumentation.ts` file so it runs once when the server starts:\n *\n * ```ts\n * // instrumentation.ts\n * export async function register() {\n * const { register } = await import(\"@configdirector/nextjs-sdk/server\");\n * await register({ serverSdkKey: process.env.CONFIGDIRECTOR_SERVER_KEY! });\n * }\n * ```\n */\nexport async function register(options: RegisterOptions): Promise<void> {\n if (process.env[\"NEXT_RUNTIME\"] !== \"nodejs\") {\n return;\n }\n\n if (!options.serverSdkKey) {\n const message =\n \"The ConfigDirector serverSdkKey must be provided to register(). You can pass it via process.env.CONFIGDIRECTOR_SERVER_KEY.\";\n createDefaultLogger().error(message);\n throw new ConfigDirectorInitializationError(message);\n }\n\n if (!globalThis.__configDirectorServerClient) {\n const { DefaultConfigDirectorClient } = await import(\"@js-server-sdk/DefaultConfigDirectorClient\");\n const { serverSdkKey, ...clientOptions } = options;\n globalThis.__configDirectorAppMeta = {\n appName: options.metadata?.appName,\n appVersion: options.metadata?.appVersion,\n };\n const client = new DefaultConfigDirectorClient(\n serverSdkKey,\n { sdkName: \"nextjs-sdk\", sdkVersion: \"__VERSION__\" },\n clientOptions,\n );\n globalThis.__configDirectorServerClient = client;\n await client.initialize();\n }\n}\n\nexport function getAppMeta(): { appName?: string; appVersion?: string } {\n return globalThis.__configDirectorAppMeta ?? {};\n}\n\nexport function getConfigClient(): ConfigDirectorClient {\n if (!globalThis.__configDirectorServerClient) {\n throw new ConfigDirectorInitializationError(\n \"[ConfigDirector] Server client not initialized. Make sure to call register() in your instrumentation.ts file before using the SDK.\",\n );\n }\n return globalThis.__configDirectorServerClient;\n}\n","import type { ConfigDirectorContext, ConfigState } from \"@js-server-sdk/types\";\nimport { getConfigClient } from \"./singleton\";\nimport { createDefaultLogger } from \"./logger\";\n\nconst logger = createDefaultLogger();\n\nexport type GenerateSsrConfigSetOptions = {\n /** User context for targeting rule evaluation. */\n context?: ConfigDirectorContext;\n /**\n * Restrict the returned config set to these keys. When omitted, all known configs are\n * returned. Useful when you want to pre-evaluate only a specific subset of flags.\n */\n configKeys?: string[];\n};\n\n/**\n * Evaluates configs server-side and returns a map of {@link ConfigState} objects keyed by\n * config key, suitable for passing as `initialConfigs` to `ConfigDirectorProvider`.\n *\n * Returns an empty object when the server SDK isn't initialized yet (e.g. during\n * `next build` static analysis without a live connection).\n *\n * In most cases you don't need this directly — use the `ConfigDirectorProvider` exported\n * from `@configdirector/nextjs-sdk/server`, which calls this automatically.\n */\nexport function generateSsrConfigSet(options?: GenerateSsrConfigSetOptions): Record<string, ConfigState> {\n try {\n return getConfigClient().getAllConfigs(options);\n } catch (error) {\n logger.error(\"Error retrieving SSR config set:\", error);\n return {};\n }\n}\n","import type { PropsWithChildren } from \"react\";\nimport { ConfigDirectorProvider as ClientProvider } from \"@configdirector/nextjs-sdk/client\";\nimport type { ConfigDirectorProviderOptions } from \"../client/types\";\nimport { generateSsrConfigSet } from \"./ssr\";\nimport { getAppMeta } from \"./singleton\";\n\n/**\n * Props for {@link ConfigDirectorProvider}. Identical to the client provider options\n * except `initialConfigs` is omitted — SSR-evaluated values are injected automatically.\n */\nexport type ConfigDirectorProviderProps = Omit<ConfigDirectorProviderOptions, \"initialConfigs\"> & {\n /**\n * Restrict SSR pre-evaluation to these config keys. When omitted, all known configs are\n * pre-evaluated. Useful when you have a large config set and only need a subset hydrated\n * on this layout.\n */\n configKeys?: string[];\n};\n\n/**\n * React Server Component wrapper around the ConfigDirector client provider.\n *\n * Place this in your root layout. It pre-evaluates all configs on the server using the\n * provided context and passes them to the client provider, preventing any flash of wrong\n * content on hydration.\n *\n * Requires Next.js 13+ (App Router) and React 18+.\n *\n * Read `sdkKey` from a plain environment variable (e.g. `CONFIGDIRECTOR_CLIENT_KEY`), NOT one\n * prefixed with `NEXT_PUBLIC_` — even here, inside a Server Component. Next.js substitutes\n * `NEXT_PUBLIC_*` references with a literal string at compile time wherever they appear in\n * code it bundles, with no exemption for Server Components; that permanently freezes the\n * value into the build artifact the moment you reference it here, regardless of the two\n * deployment strategies below. A plain variable, by contrast, is read live from `process.env`\n * — its resolved value (not the variable lookup itself) is what gets passed as a prop to the\n * client provider below, which is how it safely reaches the browser without ever being baked\n * into the bundle as source.\n *\n * **Deploying one build artifact to multiple environments (e.g. one Docker image promoted\n * from staging to prod):** a plain variable is only read fresh per request if this component's\n * render actually re-runs on each request — otherwise Next.js still statically prerenders the\n * route once at build time and caches the output to a static HTML file, silently freezing\n * whichever value was set at build time. Make sure your root layout either reads a per-request\n * API like `cookies()` (as below, which forces dynamic rendering as a side effect) or adds\n * `export const dynamic = \"force-dynamic\";` if it doesn't otherwise need one. The trade-off is\n * that the route loses static generation/ISR caching, since it now renders on every request.\n *\n * **Building a separate artifact per environment:** if you'd rather keep static generation\n * (and are fine building once per environment, e.g. as a distinct step per env in CI), no\n * layout changes are needed — a plain environment variable set at build time is read once and\n * baked into the static output for that build, same as `NEXT_PUBLIC_` would be, just without\n * also exposing it to arbitrary client-side code that isn't a descendant of this provider.\n *\n * @example\n * ```tsx\n * // app/layout.tsx\n * import { ConfigDirectorProvider } from \"@configdirector/nextjs-sdk/server\";\n * import { cookies } from \"next/headers\";\n *\n * export default async function RootLayout({ children }) {\n * const userId = (await cookies()).get(\"userId\")?.value;\n * return (\n * <html>\n * <body>\n * <ConfigDirectorProvider\n * sdkKey={process.env.CONFIGDIRECTOR_CLIENT_KEY!}\n * context={{ userId }}\n * >\n * {children}\n * </ConfigDirectorProvider>\n * </body>\n * </html>\n * );\n * }\n * ```\n */\nexport async function ConfigDirectorProvider({\n children,\n configKeys,\n ...props\n}: PropsWithChildren<ConfigDirectorProviderProps>) {\n const initialConfigs = generateSsrConfigSet({ context: props.context, configKeys });\n const appMeta = getAppMeta();\n return (\n <ClientProvider\n {...props}\n appName={props.appName ?? appMeta.appName}\n appVersion={props.appVersion ?? appMeta.appVersion}\n initialConfigs={initialConfigs}>\n {children}\n </ClientProvider>\n );\n}\n"],"mappings":"oKAGA,IAAM,EAAN,KAAuE,CACrE,gBAAgB,EAAyB,CACvC,MAAO,+BAA+B,MAI1C,MAAa,GACX,EACA,IAEO,IAAI,EAAqB,GAAS,OAAQ,GAAoB,IAAI,EAAsB,CAGpF,GACX,EACA,IAEO,IAAI,EAAqB,EAAO,GAAoB,IAAI,EAAsB,CCSvF,eAAsB,EAAS,EAAyC,CAClE,WAAQ,IAAI,eAAoB,SAIpC,IAAI,CAAC,EAAQ,aAAc,CACzB,IAAM,EACJ,6HAEF,MADA,GAAqB,CAAC,MAAM,EAAQ,CAC9B,IAAI,EAAkC,EAAQ,CAGtD,GAAI,CAAC,WAAW,6BAA8B,CAC5C,GAAM,CAAE,+BAAgC,MAAM,OAAO,8CAAA,KAAA,GAAA,EAAA,EAAA,CAC/C,CAAE,eAAc,GAAG,GAAkB,EAC3C,WAAW,wBAA0B,CACnC,QAAS,EAAQ,UAAU,QAC3B,WAAY,EAAQ,UAAU,WAC/B,CACD,IAAM,EAAS,IAAI,EACjB,EACA,CAAE,QAAS,aAAc,WAAY,QAAe,CACpD,EACD,CACD,WAAW,6BAA+B,EAC1C,MAAM,EAAO,YAAY,GAI7B,SAAgB,GAAwD,CACtE,OAAO,WAAW,yBAA2B,EAAE,CAGjD,SAAgB,GAAwC,CACtD,GAAI,CAAC,WAAW,6BACd,MAAM,IAAI,EACR,qIACD,CAEH,OAAO,WAAW,6BChEpB,MAAM,EAAS,GAAqB,CAsBpC,SAAgB,EAAqB,EAAoE,CACvG,GAAI,CACF,OAAO,GAAiB,CAAC,cAAc,EAAQ,OACxC,EAAO,CAEd,OADA,EAAO,MAAM,mCAAoC,EAAM,CAChD,EAAE,EC6Cb,eAAsB,EAAuB,CAC3C,WACA,aACA,GAAG,GAC8C,CACjD,IAAM,EAAiB,EAAqB,CAAE,QAAS,EAAM,QAAS,aAAY,CAAC,CAC7E,EAAU,GAAY,CAC5B,OACE,EAACA,EAAD,CACE,GAAI,EACJ,QAAS,EAAM,SAAW,EAAQ,QAClC,WAAY,EAAM,YAAc,EAAQ,WACxB,iBACf,WACc,CAAA"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./DefaultConfigDirectorClient-BngKzHat.cjs`),t=require(`./errors-CCbuIqT8.cjs`);let n=require(`node:events`);n=e.i(n);const r=(e,n)=>{if(e.trim().length==0)throw new t.r(`Invalid config key. The key of a test value cannot be empty.`);return i(e,n)},i=(e,n)=>{switch(typeof n){case`boolean`:return{type:`boolean`,value:n?`true`:`false`};case`number`:return a(e,n);case`string`:return{type:`string`,value:n};case`object`:if(n!==null)return s(e,n,``),{type:`json`,value:JSON.stringify(n)}}throw new t.r(`Invalid test value for '${e}': ${u(n)}. Use a boolean, a number, a string, a plain object, or an array.`)},a=(e,n)=>{if(!Number.isFinite(n))throw new t.r(`Invalid test value for '${e}': ${u(n)} is not a finite number.`);if(Number.isInteger(n)){if(!Number.isSafeInteger(n))throw new t.r(`Invalid test value for '${e}': ${n} is not a safe integer, so the SDK could not read it back exactly.`);return{type:`integer`,value:String(n)}}return{type:`float`,value:o(n)}},o=e=>{let t=String(e),n=t.indexOf(`e-`);if(n<0)return t;let r=t.startsWith(`-`)?`-`:``,[i=``,a=``]=t.slice(r.length,n).split(`.`),o=Number(t.slice(n+2))-i.length;return`${r}0.${`0`.repeat(o)}${i}${a}`},s=(e,t,n)=>{if(!(t===null||typeof t==`boolean`||typeof t==`string`)){if(typeof t==`number`){if(!Number.isFinite(t))throw c(e,n,`${u(t)} is not a finite number`);return}if(Array.isArray(t)){t.forEach((t,r)=>s(e,t,`${n}[${r}]`));return}if(l(t)){for(let[r,i]of Object.entries(t))s(e,i,n?`${n}.${r}`:r);return}throw c(e,n,`${u(t)} cannot be encoded as JSON`)}},c=(e,n,r)=>new t.r(`Invalid test value for '${e}'${n?` at '${n}'`:``}: ${r}. JSON contents can hold booleans, finite numbers, strings, null, arrays, and plain objects.`),l=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},u=e=>e===null?`null`:typeof e==`function`?`a function`:typeof e==`object`?`a ${e.constructor?.name??`object`} instance`:typeof e==`symbol`?`a symbol`:String(e),d=(e,t)=>{let n=r(e,t);return{id:`test-config:${e}`,key:e,type:n.type,variations:[{name:null,value:n.value}],target:{defaultValue:n.value,rules:[]}}},f={environmentId:`test-environment`,projectId:`test-project`};var p=class{constructor(e,t){this.logger=e,this.emitter=new n.default,this.configs=new Map,this.pendingDeliveries=[],this.armed=`nothing`,this.connected=!1,this.delivering=!1,this.encodeAll(t).forEach((e,t)=>this.configs.set(t,e))}setValue(e,t){let n=d(e,t);this.configs.set(e,n),this.deliverIfConnected({...f,kind:`delta`,configs:{[e]:n}})}removeValue(e){this.configs.delete(e),this.deliverIfConnected(this.fullUpdate())}replaceValues(e){let t=this.encodeAll(e);this.configs.clear(),t.forEach((e,t)=>this.configs.set(t,e)),this.armed=`nothing`,this.deliverIfConnected(this.fullUpdate())}hold(){this.armed=`hold`}complete(){this.pendingHold?this.pendingHold.complete():this.armed===`hold`&&(this.armed=`nothing`)}fail(){this.pendingHold?this.pendingHold.fail():this.armed=`failure`}connect(e){this.endAttempt();let t=this.armed;switch(this.armed=`nothing`,t){case`failure`:return this.failNow();case`hold`:return this.holdNow(e);default:return this.connectNow(),Promise.resolve(this)}}get isConnected(){return this.connected}on(e,t){this.emitter.on(e,t)}off(e,t){t?this.emitter.off(e,t):this.emitter.removeAllListeners(e)}close(){this.endAttempt()}dispose(){this.close(),this.emitter.removeAllListeners()}endAttempt(){this.connected=!1,this.pendingHold?.end()}connectNow(){this.connected=!0,this.deliver(this.fullUpdate())}holdNow(e){return new Promise((t,n)=>{let r=setTimeout(()=>this.pendingHold?.end(),e),i=()=>{clearTimeout(r),this.pendingHold=void 0};this.pendingHold={end:()=>{i(),t(this)},complete:()=>{i(),this.connectNow(),t(this)},fail:()=>{i();let e=this.fatalError();this.emitter.emit(`connectionError`,e),n(e)}}})}failNow(){let e=this.fatalError();return this.emitter.emit(`connectionError`,e),Promise.reject(e)}fatalError(){return new t.t(`Connection failed with status: 401. Error: the test client failed this initialization. This is an unrecoverable error, will not attempt to reconnect.`,401)}deliverIfConnected(e){this.connected&&this.deliver(e)}deliver(e){if(this.pendingDeliveries.push(e),!this.delivering){this.delivering=!0;try{let e=this.pendingDeliveries.shift();for(;e;)this.emitCaught(e),e=this.pendingDeliveries.shift()}finally{this.delivering=!1}}}emitCaught(e){try{this.emitter.emit(`configBundleReceived`,e)}catch(e){this.logger.error(`[InMemoryConnection] Error dispatching a config update from the test client: `,e)}}fullUpdate(){return{...f,kind:`full`,configs:Object.fromEntries(this.configs)}}encodeAll(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,d(n,r));return t}};const m={start:()=>{},evaluatedConfig:()=>{},close:async()=>{}};var h=class{constructor(e,t){this.client=e,this.connection=t}setValue(e,t){this.connection.setValue(e,t)}removeValue(e){this.connection.removeValue(e)}replaceValues(e){this.connection.replaceValues(e)}holdInitialization(){this.connection.hold()}completeInitialization(){this.connection.complete()}failInitialization(){this.connection.fail()}};const g=(t,n)=>{let r=n?.logger??e.r(),i=new p(r,n?.values??{});return new h(new e.t(`test-client`,t,{logger:r,connection:{timeout:n?.timeout}},{transport:i,telemetry:m}),i)},_=e=>g({sdkName:`nextjs-sdk`,sdkVersion:`1.8.0`},e),v=e=>{let t=globalThis.__configDirectorServerClient;return globalThis.__configDirectorServerClient=e.client,()=>{globalThis.__configDirectorServerClient=t}};exports.ConfigDirectorConnectionError=t.t,exports.ConfigDirectorValidationError=t.r,exports.createTestClient=_,exports.installServerTestClient=v;
@@ -0,0 +1,119 @@
1
+ import { a as ConfigDirectorLogger, t as ConfigDirectorClient } from "./types-DnzM2ukj.cjs";
2
+
3
+ //#region ../shared/src/errors.d.ts
4
+ declare class ConfigDirectorConnectionError extends Error {
5
+ readonly name: string;
6
+ readonly status?: number;
7
+ constructor(message: string, status?: number);
8
+ }
9
+ declare class ConfigDirectorValidationError extends Error {
10
+ readonly name: string;
11
+ constructor(message: string);
12
+ }
13
+ //#endregion
14
+ //#region ../shared/src/testing/values.d.ts
15
+ type TestJsonValue = boolean | number | string | null | TestJsonValue[] | {
16
+ [key: string]: TestJsonValue;
17
+ };
18
+ type TestValue = boolean | number | string | TestJsonValue[] | {
19
+ [key: string]: TestJsonValue;
20
+ };
21
+ type TestValues = Record<string, TestValue>;
22
+ //#endregion
23
+ //#region ../js-server-sdk/src/testing/TestClient.d.ts
24
+ /**
25
+ * Options for {@link createTestClient}. Every option is optional.
26
+ */
27
+ type TestClientOptions = {
28
+ /**
29
+ * The config values the test client serves once its client connects, keyed by config key. The
30
+ * config type follows from each value: a boolean, an integral number (`integer`), any other
31
+ * number (`float`), a string, or a plain object or array (`json`). Every context receives the
32
+ * same value.
33
+ */
34
+ values?: TestValues;
35
+ /**
36
+ * The connection timeout of the SDK client, in milliseconds. It bounds how long a held
37
+ * `initialize` waits. Defaults to the SDK's production timeout.
38
+ */
39
+ timeout?: number;
40
+ /**
41
+ * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level.
42
+ */
43
+ logger?: ConfigDirectorLogger;
44
+ };
45
+ /**
46
+ * A real ConfigDirector client connected to an in-memory server that the test controls.
47
+ *
48
+ * The client under {@link TestClient.client} is the SDK's production client: value parsing,
49
+ * targeting evaluation, watchers, events, and readiness behave as they do against ConfigDirector.
50
+ * Only the network connection and telemetry are replaced, so no request is ever made and nothing
51
+ * is left running after the client is disposed.
52
+ */
53
+ interface TestClient {
54
+ /**
55
+ * The SDK client to hand to the code under test. It starts uninitialized, like a production
56
+ * client; `initialize` completes at once with the seeded values unless initialization is held.
57
+ */
58
+ readonly client: ConfigDirectorClient;
59
+ /**
60
+ * Stores `value` under `key` and, when the client is connected, delivers it as an update, so
61
+ * reads, watchers, and `configsUpdated` handlers see it.
62
+ */
63
+ setValue(key: string, value: TestValue): void;
64
+ /**
65
+ * Removes `key` and, when the client is connected, delivers a full update without it, so reads
66
+ * fall back to the in-code default value and watchers of `key` receive that default.
67
+ */
68
+ removeValue(key: string): void;
69
+ /**
70
+ * Replaces every stored value with `values`, disarms any armed hold or failure, and, when the
71
+ * client is connected, delivers the new values as a full update.
72
+ */
73
+ replaceValues(values: TestValues): void;
74
+ /**
75
+ * Makes the next `initialize` wait until {@link completeInitialization} or
76
+ * {@link failInitialization} is called, or until the client's timeout elapses.
77
+ */
78
+ holdInitialization(): void;
79
+ /**
80
+ * Delivers the stored values to a held `initialize`, so it completes with the client ready. When
81
+ * a hold is armed but no `initialize` has started, it disarms the hold instead.
82
+ */
83
+ completeInitialization(): void;
84
+ /**
85
+ * Fails a held `initialize` with an unrecoverable connection error, or arms the next `initialize`
86
+ * to fail. `initialize` completes promptly with the client not ready and `connectionError` fires.
87
+ */
88
+ failInitialization(): void;
89
+ }
90
+ //#endregion
91
+ //#region src/server/testing.d.ts
92
+ /**
93
+ * Creates a {@link TestClient}: a real server `ConfigDirectorClient` connected to an in-memory
94
+ * server that the test controls. No network connection is opened and no telemetry is sent. Put it
95
+ * where `register()` would put the server singleton with {@link installServerTestClient}.
96
+ *
97
+ * @param options {@link TestClientOptions}: the initial values, the client's timeout, and its logger
98
+ * @returns A {@link TestClient} whose `client` is passed to the code under test
99
+ *
100
+ * @example
101
+ * import { createTestClient, installServerTestClient } from "@configdirector/nextjs-sdk/server/testing";
102
+ *
103
+ * const testClient = createTestClient({ values: { "new-checkout": true } });
104
+ * const uninstall = installServerTestClient(testClient);
105
+ * await testClient.client.initialize();
106
+ */
107
+ declare const createTestClient: (options?: TestClientOptions) => TestClient;
108
+ /**
109
+ * Puts `testClient.client` where `register()` puts the server singleton, so `getConfigClient()`,
110
+ * `generateSsrConfigSet()`, and the server `ConfigDirectorProvider` serve its values. It does not
111
+ * initialize the client: call `await testClient.client.initialize()`, as `register()` would.
112
+ *
113
+ * @param testClient The server test client whose `client` to install
114
+ * @returns A function that restores the client installed before
115
+ */
116
+ declare const installServerTestClient: (testClient: TestClient) => (() => void);
117
+ //#endregion
118
+ export { ConfigDirectorConnectionError, ConfigDirectorValidationError, type TestClient, type TestClientOptions, type TestJsonValue, type TestValue, type TestValues, createTestClient, installServerTestClient };
119
+ //# sourceMappingURL=testing.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.cts","names":[],"sources":["../../../shared/src/errors.ts","../../../shared/src/testing/values.ts","../../../js-server-sdk/src/testing/TestClient.ts","../../src/server/testing.ts"],"mappings":";;;cAAa,6BAAA,SAAsC,KAAA;EAAA,SACxB,IAAA;EAAA,SACT,MAAA;cAEJ,OAAA,UAAiB,MAAA;AAAA;AAAA,cAQlB,6BAAA,SAAsC,KAAA;EAAA,SACxB,IAAA;cAEb,OAAA;AAAA;;;KCZF,aAAA,sCAAmD,aAAA;EAAA,CAAqB,GAAA,WAAc,aAAA;AAAA;AAAA,KAEtF,SAAA,+BAAwC,aAAA;EAAA,CAAqB,GAAA,WAAc,aAAA;AAAA;AAAA,KAE3E,UAAA,GAAa,MAAA,SAAe,SAAA;;;;ADPxC;;KEYY,iBAAA;EFZ4C;;;;;;EEmBtD,MAAA,GAAS,UAAA;EFfmC;;AAQ9C;;EEYE,OAAA;EFZsD;;;EEgBtD,MAAA,GAAS,oBAAA;AAAA;;;;;;ADzBX;;;UCoCiB,UAAA;EDpC8C;;;;EAAA,SCyCpD,MAAA,EAAQ,oBAAA;EDvCP;;;;EC6CV,QAAA,CAAS,GAAA,UAAa,KAAA,EAAO,SAAA;ED7C0C;;;;ECmDvE,WAAA,CAAY,GAAA;EDjDQ;;;;ECuDpB,aAAA,CAAc,MAAA,EAAQ,UAAA;;;AAlDxB;;EAwDE,kBAAA;EAxC6B;;;;EA8C7B,sBAAA;EA9CS;;;AAWX;EAyCE,kBAAA;AAAA;;;;;;;;;;;;;;AFpEF;;;;cGUa,gBAAA,GAAoB,OAAA,GAAU,iBAAA,KAAoB,UAAA;;;;;;;;;cAYlD,uBAAA,GAA2B,UAAA,EAAY,UAAA"}