@configdirector/nextjs-sdk 1.13.1 → 1.14.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/dist/client/index.cjs +1 -1
  2. package/dist/client/index.d.cts +2 -2
  3. package/dist/client/index.d.mts +2 -2
  4. package/dist/client/index.mjs +1 -1
  5. package/dist/client/index.mjs.map +1 -1
  6. package/dist/client/installedTestClient-Bam5r_HR.cjs +6 -0
  7. package/dist/client/installedTestClient-CL4AQC58.mjs +7 -0
  8. package/dist/client/installedTestClient-CL4AQC58.mjs.map +1 -0
  9. package/dist/client/testing.cjs +1 -1
  10. package/dist/client/testing.d.cts +12 -3
  11. package/dist/client/testing.d.cts.map +1 -1
  12. package/dist/client/testing.d.mts +12 -3
  13. package/dist/client/testing.d.mts.map +1 -1
  14. package/dist/client/testing.mjs +1 -1
  15. package/dist/client/testing.mjs.map +1 -1
  16. package/dist/client/{types-CRVL6Yi2.d.cts → types-CdyMdj5l.d.mts} +75 -7
  17. package/dist/client/types-CdyMdj5l.d.mts.map +1 -0
  18. package/dist/client/{types-B4kvU3bh.d.mts → types-P8frfCGH.d.cts} +75 -7
  19. package/dist/client/types-P8frfCGH.d.cts.map +1 -0
  20. package/dist/server/DefaultConfigDirectorClient-LQ79aY-g.mjs +6 -0
  21. package/dist/server/DefaultConfigDirectorClient-LQ79aY-g.mjs.map +1 -0
  22. package/dist/server/DefaultConfigDirectorClient-VHa0AfMj.cjs +5 -0
  23. package/dist/server/{errors-Do5xWGgb.d.cts → errors-CkxBFyZy.d.cts} +76 -7
  24. package/dist/server/errors-CkxBFyZy.d.cts.map +1 -0
  25. package/dist/server/{errors-CxXHE84y.d.mts → errors-CsEeGYMl.d.mts} +76 -7
  26. package/dist/server/errors-CsEeGYMl.d.mts.map +1 -0
  27. package/dist/server/index.cjs +1 -1
  28. package/dist/server/index.d.cts +2 -2
  29. package/dist/server/index.d.cts.map +1 -1
  30. package/dist/server/index.d.mts +2 -2
  31. package/dist/server/index.d.mts.map +1 -1
  32. package/dist/server/index.mjs +1 -1
  33. package/dist/server/testing.cjs +1 -1
  34. package/dist/server/testing.d.cts +12 -3
  35. package/dist/server/testing.d.cts.map +1 -1
  36. package/dist/server/testing.d.mts +12 -3
  37. package/dist/server/testing.d.mts.map +1 -1
  38. package/dist/server/testing.mjs +1 -1
  39. package/dist/server/testing.mjs.map +1 -1
  40. package/package.json +1 -1
  41. package/dist/client/installedTestClient-BqVnonO8.mjs +0 -7
  42. package/dist/client/installedTestClient-BqVnonO8.mjs.map +0 -1
  43. package/dist/client/installedTestClient-DM_qeRk9.cjs +0 -6
  44. package/dist/client/types-B4kvU3bh.d.mts.map +0 -1
  45. package/dist/client/types-CRVL6Yi2.d.cts.map +0 -1
  46. package/dist/server/DefaultConfigDirectorClient-BfpJX-Ni.mjs +0 -6
  47. package/dist/server/DefaultConfigDirectorClient-BfpJX-Ni.mjs.map +0 -1
  48. package/dist/server/DefaultConfigDirectorClient-C4cOinqO.cjs +0 -5
  49. package/dist/server/errors-CxXHE84y.d.mts.map +0 -1
  50. package/dist/server/errors-Do5xWGgb.d.cts.map +0 -1
@@ -1 +1 @@
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":";;;;;QASQ,MAAA;EAAA,IACF,4BAAA,EAA8B,oBAAA;EAAA,IAC9B,oCAAA,EAAsC,cAAA;EAAA,IACtC,uBAAA;IAA2B,OAAA;IAAkB,UAAA;EAAA;AAAA;;;;;;KAQvC,eAAA;EARuC;;;;EAc7C,YAAA;AAAA,IACE,2BAAA,KACH,oBAAA;EAAyB,YAAA;AAAA;;;;;;;;AAuB9B;;;;;;;;;AAwCA;;;;;iBAxCsB,QAAA,CAAS,OAAA,EAAS,eAAA,GAAkB,OAAA;AAA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IhB,GAAA,CAAI,cAAA,MAAoB,IAAA,gBAAoB,KAAA,EAAO,0BAAA,EAA4B,OAAA,aAAoB,IAAA;AAAA;;;KC/BnG,6BAAA;EJdN;;;;EImBJ,MAAA;EACA,OAAA;EACA,UAAA;EJZU;;;EIgBV,GAAA;EJVI;;;EIcJ,OAAA;EJZwC;;AAuB1C;;;;;;;;EIAE,IAAA,GAAO,cAAA;EJwCO;;;;;AAQhB;EIzCE,MAAA,GAAS,eAAA;;;;;;EAMT,eAAA;EH1DU;;;EG8DV,OAAA,GAAU,qBAAA;EH5DV;;;;;AAkBF;;EGkDE,mBAAA;EHlD6C;;;EGsD7C,QAAA,GAAW,0BAAA;EAEX,KAAA,GAAQ,WAAA;EHxDqC;;;;;;;;;ACmF/C;EEhBE,cAAA,GAAiB,MAAA,SAAe,WAAA;AAAA;;;;;;AJxFJ;KKOlB,2BAAA,GAA8B,IAAA,CAAK,6BAAA;;;;;;EAM7C,UAAA;AAAA;;;;;;;ALEF;;;;;;;;;;AA+BA;;;;;;;;;AAwCA;;;;;AAQA;;;;;;;;AC7FA;;;;;;;;;AAoBA;;;;;;;;;;iBIoDsB,sBAAA,CAAA;EACpB,QAAA;EACA,UAAA;EAAA,GACG;AAAA,GACF,iBAAA,CAAkB,2BAAA,IAA4B,OAAA,CAAA,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cClEpC,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":";;;;;QASQ,MAAA;EAAA,IACF,4BAAA,EAA8B,oBAAA;EAAA,IAC9B,oCAAA,EAAsC,cAAA;EAAA,IACtC,uBAAA;IAA2B,OAAA;IAAkB,UAAA;EAAA;AAAA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ectorMetaContext, h as ConfigDirectorLoggingLevel, i as ConfigDirectorClient, m as ConfigDirectorLogger, n as ConfigDirectorInitializationError, o as OfflineClientOptions, p as ConfigDirectorLogMessageDecorator, s as OfflineValue, v as ConfigState, x as EvaluationReason, y as ConfigValueType } from "./errors-CxXHE84y.mjs";
1
+ import { E as Variation, S as TrackOptions, T as TrackedEventDetails, _ as ConfigEvaluation, a as ConfigDirectorClientOptions, b as ConnectionMode, c as OfflineValues, d as NativeValues, f as ConfigDirectorContext, g as ConfigDirectorMetaContext, h as ConfigDirectorLoggingLevel, i as ConfigDirectorClient, m as ConfigDirectorLogger, n as ConfigDirectorInitializationError, o as OfflineClientOptions, p as ConfigDirectorLogMessageDecorator, s as OfflineValue, v as ConfigState, w as TrackedEventDetailValue, x as EvaluationReason, y as ConfigValueType } from "./errors-CsEeGYMl.mjs";
2
2
  import * as _$react_jsx_runtime0 from "react/jsx-runtime";
3
3
  import { PropsWithChildren } from "react";
4
4
 
@@ -273,5 +273,5 @@ declare function ConfigDirectorProvider({
273
273
  //#region src/server/logger.d.ts
274
274
  declare const createConsoleLogger: (level: ConfigDirectorLoggingLevel, messageDecorator?: ConfigDirectorLogMessageDecorator) => DefaultConsoleLogger;
275
275
  //#endregion
276
- export { type ConfigDirectorClient, type ConfigDirectorClientOptions, type ConfigDirectorContext, ConfigDirectorInitializationError, type ConfigDirectorLogger, type ConfigDirectorMetaContext, ConfigDirectorProvider, type ConfigDirectorProviderProps, type ConfigEvaluation, type ConfigValueType, type ConnectionMode, type EvaluationReason, type GenerateSsrConfigSetOptions, type OfflineClientOptions, type OfflineValue, type OfflineValues, type RegisterOptions, createConsoleLogger, generateSsrConfigSet, getAppMeta, getConfigClient, register };
276
+ export { type ConfigDirectorClient, type ConfigDirectorClientOptions, type ConfigDirectorContext, ConfigDirectorInitializationError, type ConfigDirectorLogger, type ConfigDirectorMetaContext, ConfigDirectorProvider, type ConfigDirectorProviderProps, type ConfigEvaluation, type ConfigValueType, type ConnectionMode, type EvaluationReason, type GenerateSsrConfigSetOptions, type OfflineClientOptions, type OfflineValue, type OfflineValues, type RegisterOptions, type TrackOptions, type TrackedEventDetailValue, type TrackedEventDetails, type Variation, createConsoleLogger, generateSsrConfigSet, getAppMeta, getConfigClient, register };
277
277
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
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":";;;;;QASQ,MAAA;EAAA,IACF,4BAAA,EAA8B,oBAAA;EAAA,IAC9B,oCAAA,EAAsC,cAAA;EAAA,IACtC,uBAAA;IAA2B,OAAA;IAAkB,UAAA;EAAA;AAAA;;;;;;KAQvC,eAAA;EARuC;;;;EAc7C,YAAA;AAAA,IACE,2BAAA,KACH,oBAAA;EAAyB,YAAA;AAAA;;;;;;;;AAuB9B;;;;;;;;;AAwCA;;;;;iBAxCsB,QAAA,CAAS,OAAA,EAAS,eAAA,GAAkB,OAAA;AAAA,iBAwC1C,UAAA,CAAA;EAAgB,OAAA;EAAkB,UAAA;AAAA;AAAA,iBAQlC,eAAA,CAAA,GAAmB,oBAAA;;;KC7FvB,2BAAA;oDAEV,OAAA,GAAU,qBAAA;;ADHkB;;;ECQ5B,UAAA;AAAA;;;;;;;;;;;iBAac,oBAAA,CAAqB,OAAA,GAAU,2BAAA,GAA8B,MAAA,SAAe,WAAA;;;AC+L5F;;;;AAAA,KA5GY,eAAA,GAAgB,YAAA;AAAA,KA4GhB,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;EACnD,kBAAA,GAAq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;KKOlB,2BAAA,GAA8B,IAAA,CAAK,6BAAA;;;;;;EAM7C,UAAA;AAAA;;;;;;;ALEF;;;;;;;;;;AA+BA;;;;;;;;;AAwCA;;;;;AAQA;;;;;;;;AC7FA;;;;;;;;;AAoBA;;;;;;;;;;iBIoDsB,sBAAA,CAAA;EACpB,QAAA;EACA,UAAA;EAAA,GACG;AAAA,GACF,iBAAA,CAAkB,2BAAA,IAA4B,OAAA,CAAA,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cClEpC,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":";;;;;QASQ,MAAA;EAAA,IACF,4BAAA,EAA8B,oBAAA;EAAA,IAC9B,oCAAA,EAAsC,cAAA;EAAA,IACtC,uBAAA;IAA2B,OAAA;IAAkB,UAAA;EAAA;AAAA;;;;;;KAQvC,eAAA;EARuC;;;;EAc7C,YAAA;AAAA,IACE,2BAAA,KACH,oBAAA;EAAyB,YAAA;AAAA;;;;;;;;AAuB9B;;;;;;;;;AAwCA;;;;;iBAxCsB,QAAA,CAAS,OAAA,EAAS,eAAA,GAAkB,OAAA;AAAA,iBAwC1C,UAAA,CAAA;EAAgB,OAAA;EAAkB,UAAA;AAAA;AAAA,iBAQlC,eAAA,CAAA,GAAmB,oBAAA;;;KC7FvB,2BAAA;oDAEV,OAAA,GAAU,qBAAA;;ADHkB;;;ECQ5B,UAAA;AAAA;;;;;;;;;;;iBAac,oBAAA,CAAqB,OAAA,GAAU,2BAAA,GAA8B,MAAA,SAAe,WAAA;;;ACgM5F;;;;AAAA,KA5GY,eAAA,GAAgB,YAAA;AAAA,KA4GhB,WAAA;EACV,WAAA,GAAc,WAAA,kBAA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AAA;EH5DV;;;;;AAkBF;;EGkDE,mBAAA;EHlD6C;;;EGsD7C,QAAA,GAAW,0BAAA;EAEX,KAAA,GAAQ,WAAA;EHxDqC;;;;;;;;;ACoF/C;EEjBE,cAAA,GAAiB,MAAA,SAAe,WAAA;AAAA;;;;;;AJxFJ;KKOlB,2BAAA,GAA8B,IAAA,CAAK,6BAAA;;;;;;EAM7C,UAAA;AAAA;;;;;;;ALEF;;;;;;;;;;AA+BA;;;;;;;;;AAwCA;;;;;AAQA;;;;;;;;AC7FA;;;;;;;;;AAoBA;;;;;;;;;;iBIoDsB,sBAAA,CAAA;EACpB,QAAA;EACA,UAAA;EAAA,GACG;AAAA,GACF,iBAAA,CAAkB,2BAAA,IAA4B,OAAA,CAAA,oBAAA,CAAA,GAAA,CAAA,OAAA;;;cClEpC,mBAAA,GACX,KAAA,EAAO,0BAAA,EACP,gBAAA,GAAmB,iCAAA,KAAiC,oBAAA"}
@@ -1,2 +1,2 @@
1
- import{i as e,o as t,t as n}from"./native-values-CfqV9hAq.mjs";import{ConfigDirectorProvider as r}from"@configdirector/nextjs-sdk/client";import{jsx as i}from"react/jsx-runtime";var a=class{decorateMessage(e){return`[ConfigDirector:nextjs-sdk] ${e}`}};const o=(e,n)=>new t(e??`warn`,n??new a),s=(e,n)=>new t(e,n??new a);async function c(t){if(process.env.NEXT_RUNTIME===`nodejs`){let n=t.connection?.mode??`streaming`;if(n!==`offline`&&!t.serverSdkKey){let t=`The ConfigDirector serverSdkKey must be provided to register(). You can pass it via process.env.CONFIGDIRECTOR_SERVER_KEY.`;throw o().error(t),new e(t)}if(!globalThis.__configDirectorServerClient){let{DefaultConfigDirectorClient:e}=await import(`./DefaultConfigDirectorClient-BfpJX-Ni.mjs`).then(e=>e.n),{serverSdkKey:r,...i}=t;globalThis.__configDirectorAppMeta={appName:t.metadata?.appName,appVersion:t.metadata?.appVersion},globalThis.__configDirectorServerConnectionMode=n;let a=new e(r,{sdkName:`nextjs-sdk`,sdkVersion:`1.13.1`},i);globalThis.__configDirectorServerClient=a;try{await a.initialize()}catch(e){throw globalThis.__configDirectorServerClient=void 0,globalThis.__configDirectorServerConnectionMode=void 0,globalThis.__configDirectorAppMeta=void 0,a.dispose(),e}}}}function l(){return globalThis.__configDirectorAppMeta??{}}function u(){return globalThis.__configDirectorServerConnectionMode}function d(){if(!globalThis.__configDirectorServerClient)throw new e(`[ConfigDirector] Server client not initialized. Make sure to call register() in your instrumentation.ts file before using the SDK.`);return globalThis.__configDirectorServerClient}const f=o();function p(e){try{return d().getAllConfigs(e)}catch(e){return f.error(`Error retrieving SSR config set:`,e),{}}}const m=(e,t)=>e.mode!==void 0||e.values!==void 0?`as-given`:t===`offline`?`inherit-offline`:`connect`,h=e=>typeof e.value==`string`,g=e=>Object.fromEntries(Object.values(e).filter(h).map(e=>[e.key,n(e.type,e.value)]));async function _({children:e,configKeys:t,...n}){let a=p({context:n.context,configKeys:t}),o=l();return i(r,{...n,...v(a,n),appName:n.appName??o.appName,appVersion:n.appVersion??o.appVersion,initialConfigs:a,children:e})}const v=(e,t)=>{switch(m(t,u())){case`as-given`:return{};case`inherit-offline`:return{mode:`offline`,values:g(e)};case`connect`:return{}}};export{e as ConfigDirectorInitializationError,_ as ConfigDirectorProvider,s as createConsoleLogger,p as generateSsrConfigSet,l as getAppMeta,d as getConfigClient,c as register};
1
+ import{i as e,o as t,t as n}from"./native-values-CfqV9hAq.mjs";import{ConfigDirectorProvider as r}from"@configdirector/nextjs-sdk/client";import{jsx as i}from"react/jsx-runtime";var a=class{decorateMessage(e){return`[ConfigDirector:nextjs-sdk] ${e}`}};const o=(e,n)=>new t(e??`warn`,n??new a),s=(e,n)=>new t(e,n??new a);async function c(t){if(process.env.NEXT_RUNTIME===`nodejs`){let n=t.connection?.mode??`streaming`;if(n!==`offline`&&!t.serverSdkKey){let t=`The ConfigDirector serverSdkKey must be provided to register(). You can pass it via process.env.CONFIGDIRECTOR_SERVER_KEY.`;throw o().error(t),new e(t)}if(!globalThis.__configDirectorServerClient){let{DefaultConfigDirectorClient:e}=await import(`./DefaultConfigDirectorClient-LQ79aY-g.mjs`).then(e=>e.n),{serverSdkKey:r,...i}=t;globalThis.__configDirectorAppMeta={appName:t.metadata?.appName,appVersion:t.metadata?.appVersion},globalThis.__configDirectorServerConnectionMode=n;let a=new e(r,{sdkName:`nextjs-sdk`,sdkVersion:`1.14.0`},i);globalThis.__configDirectorServerClient=a;try{await a.initialize()}catch(e){throw globalThis.__configDirectorServerClient=void 0,globalThis.__configDirectorServerConnectionMode=void 0,globalThis.__configDirectorAppMeta=void 0,a.dispose(),e}}}}function l(){return globalThis.__configDirectorAppMeta??{}}function u(){return globalThis.__configDirectorServerConnectionMode}function d(){if(!globalThis.__configDirectorServerClient)throw new e(`[ConfigDirector] Server client not initialized. Make sure to call register() in your instrumentation.ts file before using the SDK.`);return globalThis.__configDirectorServerClient}const f=o();function p(e){try{return d().getAllConfigs(e)}catch(e){return f.error(`Error retrieving SSR config set:`,e),{}}}const m=(e,t)=>e.mode!==void 0||e.values!==void 0?`as-given`:t===`offline`?`inherit-offline`:`connect`,h=e=>typeof e.value==`string`,g=e=>Object.fromEntries(Object.values(e).filter(h).map(e=>[e.key,n(e.type,e.value)]));async function _({children:e,configKeys:t,...n}){let a=p({context:n.context,configKeys:t}),o=l();return i(r,{...n,...v(a,n),appName:n.appName??o.appName,appVersion:n.appVersion??o.appVersion,initialConfigs:a,children:e})}const v=(e,t)=>{switch(m(t,u())){case`as-given`:return{};case`inherit-offline`:return{mode:`offline`,values:g(e)};case`connect`:return{}}};export{e as ConfigDirectorInitializationError,_ as ConfigDirectorProvider,s as createConsoleLogger,p as generateSsrConfigSet,l as getAppMeta,d as getConfigClient,c as register};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./DefaultConfigDirectorClient-C4cOinqO.cjs`),t=require(`./native-values-UCK4hh1Z.cjs`);let n=require(`node:events`);n=e.o(n);const r={environmentId:`test-environment`,projectId:`test-project`};var i=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=this.encode(e,t);this.configs.set(e,n),this.deliverIfConnected({...r,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.r(`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{...r,kind:`full`,configs:Object.fromEntries(this.configs)}}encodeAll(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,this.encode(n,r));return t}encode(t,n){return e.a(`test-config:${t}`,t,n)}},a=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 o=(t,n)=>{let r=n?.logger??e.i(),o=new i(r,n?.values??{});return new a(new e.t(`test-client`,t,{logger:r,connection:{timeout:n?.timeout}},{transport:o,telemetry:e.r}),o)},s=e=>o({sdkName:`nextjs-sdk`,sdkVersion:`1.13.1`},e),c=e=>{let t=globalThis.__configDirectorServerClient;return globalThis.__configDirectorServerClient=e.client,()=>{globalThis.__configDirectorServerClient=t}};exports.ConfigDirectorConnectionError=t.r,exports.ConfigDirectorValidationError=t.a,exports.createTestClient=s,exports.installServerTestClient=c;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./DefaultConfigDirectorClient-VHa0AfMj.cjs`),t=require(`./native-values-UCK4hh1Z.cjs`);let n=require(`node:events`);n=e.s(n);const r=(e,t)=>({name:e.name,...t===void 0?{}:{context:t},...e.value===void 0?{}:{value:e.value},...e.details===void 0?{}:{details:e.details}});var i=class{constructor(e){this.logger=e,this.events=[]}record(t,n){switch(t.warnings.forEach(t=>this.logger.warn(e.i[t])),t.outcome){case`dropped`:return;case`admitted`:this.events.push(r(t.entry,n));return}}};const a={environmentId:`test-environment`,projectId:`test-project`};var o=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=this.encode(e,t);this.configs.set(e,n),this.deliverIfConnected({...a,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.r(`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{...a,kind:`full`,configs:Object.fromEntries(this.configs)}}encodeAll(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,this.encode(n,r));return t}encode(t,n){return e.o(`test-config:${t}`,t,n)}},s=class{constructor(e,t,n){this.client=e,this.connection=t,this.trackedEvents=n}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 c=(t,n)=>{let r=n?.logger??e.a(),a=new o(r,n?.values??{}),c=new i(r);return new s(new e.t(`test-client`,t,{logger:r,connection:{timeout:n?.timeout}},{transport:a,telemetry:{...e.r,trackedEvent:(e,t)=>c.record(e,t)}}),a,c.events)},l=e=>c({sdkName:`nextjs-sdk`,sdkVersion:`1.14.0`},e),u=e=>{let t=globalThis.__configDirectorServerClient;return globalThis.__configDirectorServerClient=e.client,()=>{globalThis.__configDirectorServerClient=t}};exports.ConfigDirectorConnectionError=t.r,exports.ConfigDirectorValidationError=t.a,exports.createTestClient=l,exports.installServerTestClient=u;
@@ -1,4 +1,4 @@
1
- import { d as NativeValues, i as ConfigDirectorClient, l as NativeJsonValue, m as ConfigDirectorLogger, r as ConfigDirectorValidationError, t as ConfigDirectorConnectionError, u as NativeValue } from "./errors-Do5xWGgb.cjs";
1
+ import { C as TrackedEvent, T as TrackedEventDetails, d as NativeValues, i as ConfigDirectorClient, l as NativeJsonValue, m as ConfigDirectorLogger, r as ConfigDirectorValidationError, t as ConfigDirectorConnectionError, u as NativeValue, w as TrackedEventDetailValue } from "./errors-CkxBFyZy.cjs";
2
2
 
3
3
  //#region ../js-server-sdk/src/testing/TestClient.d.ts
4
4
  /**
@@ -20,7 +20,8 @@ type TestClientOptions = {
20
20
  /**
21
21
  * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level. Since
22
22
  * the test client sends no telemetry, every read that supplies a context with an invalid kind
23
- * logs an error, rather than each invalid kind once per telemetry interval.
23
+ * logs an error, rather than each invalid kind once per telemetry interval. For the same reason,
24
+ * every tracked event that is not recorded as it was tracked logs a warning.
24
25
  */
25
26
  logger?: ConfigDirectorLogger;
26
27
  };
@@ -68,6 +69,14 @@ interface TestClient {
68
69
  * to fail. `initialize` completes promptly with the client not ready and `connectionError` fires.
69
70
  */
70
71
  failInitialization(): void;
72
+ /**
73
+ * Every event the code under test tracked through the client, in call order, as the SDK would
74
+ * report it: an event whose name does not have 1 to 150 characters is not recorded, and a value
75
+ * or details the SDK would leave out are missing from the record. A context whose kind is
76
+ * invalid is not recorded with its event. The limit of 1,000 events per telemetry batch does not
77
+ * apply.
78
+ */
79
+ readonly trackedEvents: TrackedEvent[];
71
80
  }
72
81
  //#endregion
73
82
  //#region src/server/testing.d.ts
@@ -97,5 +106,5 @@ declare const createTestClient: (options?: TestClientOptions) => TestClient;
97
106
  */
98
107
  declare const installServerTestClient: (testClient: TestClient) => (() => void);
99
108
  //#endregion
100
- export { ConfigDirectorConnectionError, ConfigDirectorValidationError, type TestClient, type TestClientOptions, type NativeJsonValue as TestJsonValue, type NativeValue as TestValue, type NativeValues as TestValues, createTestClient, installServerTestClient };
109
+ export { ConfigDirectorConnectionError, ConfigDirectorValidationError, type TestClient, type TestClientOptions, type NativeJsonValue as TestJsonValue, type NativeValue as TestValue, type NativeValues as TestValues, type TrackedEvent, type TrackedEventDetailValue, type TrackedEventDetails, createTestClient, installServerTestClient };
101
110
  //# sourceMappingURL=testing.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.cts","names":[],"sources":["../../../js-server-sdk/src/testing/TestClient.ts","../../src/server/testing.ts"],"mappings":";;;;AAYA;;KAAY,iBAAA;EAkBmB;;;;;;EAX7B,MAAA,GAAS,YAAA;EAWoB;AAW/B;;;EAjBE,OAAA;EA4B6B;;;;;EAtB7B,MAAA,GAAS,oBAAA;AAAA;;;;;;;;;UAWM,UAAA;EAmCf;;;;EAAA,SA9BS,MAAA,EAAQ,oBAAA;;;ACxBnB;;ED8BE,QAAA,CAAS,GAAA,UAAa,KAAA,EAAO,WAAA;EC5B9B;;;;EDkCC,WAAA,CAAY,GAAA;EClCb;AAUD;;;ED8BE,aAAA,CAAc,MAAA,EAAQ,YAAA;EC9BsC;;;;EDoC5D,kBAAA;;;;;EAMA,sBAAA;;;;;EAMA,kBAAA;AAAA;;;;;;;;;;;;;AAzCF;;;;;cCnBa,gBAAA,GAAoB,OAAA,GAAU,iBAAA,KAAoB,UAAA;;;;;;;;;cAYlD,uBAAA,GAA2B,UAAA,EAAY,UAAA"}
1
+ {"version":3,"file":"testing.d.cts","names":[],"sources":["../../../js-server-sdk/src/testing/TestClient.ts","../../src/server/testing.ts"],"mappings":";;;AAcA;;;AAAA,KAAY,iBAAA;EAOV;;;;;;EAAA,MAAA,GAAS,YAAA;EAuBM;;;;EAlBf,OAAA;EAyCsB;;;;;;EAlCtB,MAAA,GAAS,oBAAA;AAAA;;;;;;;;;UAWM,UAAA;EAyCf;;;;EAAA,SApCS,MAAA,EAAQ,oBAAA;;;;AC1BnB;EDgCE,QAAA,CAAS,GAAA,UAAa,KAAA,EAAO,WAAA;;;;;EAM7B,WAAA,CAAY,GAAA;ECpCb;;AAUD;;EDgCE,aAAA,CAAc,MAAA,EAAQ,YAAA;EChC4B;;;;EDsClD,kBAAA;;;;;EAMA,sBAAA;;;;;EAMA,kBAAA;;;;;;;;WASS,aAAA,EAAe,YAAA;AAAA;;;;;;;;;;;;AAlD1B;;;;;;cCrBa,gBAAA,GAAoB,OAAA,GAAU,iBAAA,KAAoB,UAAA;;;;;;;;;cAYlD,uBAAA,GAA2B,UAAA,EAAY,UAAA"}
@@ -1,4 +1,4 @@
1
- import { d as NativeValues, i as ConfigDirectorClient, l as NativeJsonValue, m as ConfigDirectorLogger, r as ConfigDirectorValidationError, t as ConfigDirectorConnectionError, u as NativeValue } from "./errors-CxXHE84y.mjs";
1
+ import { C as TrackedEvent, T as TrackedEventDetails, d as NativeValues, i as ConfigDirectorClient, l as NativeJsonValue, m as ConfigDirectorLogger, r as ConfigDirectorValidationError, t as ConfigDirectorConnectionError, u as NativeValue, w as TrackedEventDetailValue } from "./errors-CsEeGYMl.mjs";
2
2
 
3
3
  //#region ../js-server-sdk/src/testing/TestClient.d.ts
4
4
  /**
@@ -20,7 +20,8 @@ type TestClientOptions = {
20
20
  /**
21
21
  * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level. Since
22
22
  * the test client sends no telemetry, every read that supplies a context with an invalid kind
23
- * logs an error, rather than each invalid kind once per telemetry interval.
23
+ * logs an error, rather than each invalid kind once per telemetry interval. For the same reason,
24
+ * every tracked event that is not recorded as it was tracked logs a warning.
24
25
  */
25
26
  logger?: ConfigDirectorLogger;
26
27
  };
@@ -68,6 +69,14 @@ interface TestClient {
68
69
  * to fail. `initialize` completes promptly with the client not ready and `connectionError` fires.
69
70
  */
70
71
  failInitialization(): void;
72
+ /**
73
+ * Every event the code under test tracked through the client, in call order, as the SDK would
74
+ * report it: an event whose name does not have 1 to 150 characters is not recorded, and a value
75
+ * or details the SDK would leave out are missing from the record. A context whose kind is
76
+ * invalid is not recorded with its event. The limit of 1,000 events per telemetry batch does not
77
+ * apply.
78
+ */
79
+ readonly trackedEvents: TrackedEvent[];
71
80
  }
72
81
  //#endregion
73
82
  //#region src/server/testing.d.ts
@@ -97,5 +106,5 @@ declare const createTestClient: (options?: TestClientOptions) => TestClient;
97
106
  */
98
107
  declare const installServerTestClient: (testClient: TestClient) => (() => void);
99
108
  //#endregion
100
- export { ConfigDirectorConnectionError, ConfigDirectorValidationError, type TestClient, type TestClientOptions, type NativeJsonValue as TestJsonValue, type NativeValue as TestValue, type NativeValues as TestValues, createTestClient, installServerTestClient };
109
+ export { ConfigDirectorConnectionError, ConfigDirectorValidationError, type TestClient, type TestClientOptions, type NativeJsonValue as TestJsonValue, type NativeValue as TestValue, type NativeValues as TestValues, type TrackedEvent, type TrackedEventDetailValue, type TrackedEventDetails, createTestClient, installServerTestClient };
101
110
  //# sourceMappingURL=testing.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.mts","names":[],"sources":["../../../js-server-sdk/src/testing/TestClient.ts","../../src/server/testing.ts"],"mappings":";;;;AAYA;;KAAY,iBAAA;EAkBmB;;;;;;EAX7B,MAAA,GAAS,YAAA;EAWoB;AAW/B;;;EAjBE,OAAA;EA4B6B;;;;;EAtB7B,MAAA,GAAS,oBAAA;AAAA;;;;;;;;;UAWM,UAAA;EAmCf;;;;EAAA,SA9BS,MAAA,EAAQ,oBAAA;;;ACxBnB;;ED8BE,QAAA,CAAS,GAAA,UAAa,KAAA,EAAO,WAAA;EC5B9B;;;;EDkCC,WAAA,CAAY,GAAA;EClCb;AAUD;;;ED8BE,aAAA,CAAc,MAAA,EAAQ,YAAA;EC9BsC;;;;EDoC5D,kBAAA;;;;;EAMA,sBAAA;;;;;EAMA,kBAAA;AAAA;;;;;;;;;;;;;AAzCF;;;;;cCnBa,gBAAA,GAAoB,OAAA,GAAU,iBAAA,KAAoB,UAAA;;;;;;;;;cAYlD,uBAAA,GAA2B,UAAA,EAAY,UAAA"}
1
+ {"version":3,"file":"testing.d.mts","names":[],"sources":["../../../js-server-sdk/src/testing/TestClient.ts","../../src/server/testing.ts"],"mappings":";;;AAcA;;;AAAA,KAAY,iBAAA;EAOV;;;;;;EAAA,MAAA,GAAS,YAAA;EAuBM;;;;EAlBf,OAAA;EAyCsB;;;;;;EAlCtB,MAAA,GAAS,oBAAA;AAAA;;;;;;;;;UAWM,UAAA;EAyCf;;;;EAAA,SApCS,MAAA,EAAQ,oBAAA;;;;AC1BnB;EDgCE,QAAA,CAAS,GAAA,UAAa,KAAA,EAAO,WAAA;;;;;EAM7B,WAAA,CAAY,GAAA;ECpCb;;AAUD;;EDgCE,aAAA,CAAc,MAAA,EAAQ,YAAA;EChC4B;;;;EDsClD,kBAAA;;;;;EAMA,sBAAA;;;;;EAMA,kBAAA;;;;;;;;WASS,aAAA,EAAe,YAAA;AAAA;;;;;;;;;;;;AAlD1B;;;;;;cCrBa,gBAAA,GAAoB,OAAA,GAAU,iBAAA,KAAoB,UAAA;;;;;;;;;cAYlD,uBAAA,GAA2B,UAAA,EAAY,UAAA"}
@@ -1,2 +1,2 @@
1
- import{a as e,i as t,r as n,t as r}from"./DefaultConfigDirectorClient-BfpJX-Ni.mjs";import{a as i,r as a}from"./native-values-CfqV9hAq.mjs";import o from"node:events";const s={environmentId:`test-environment`,projectId:`test-project`};var c=class{constructor(e,t){this.logger=e,this.emitter=new o,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=this.encode(e,t);this.configs.set(e,n),this.deliverIfConnected({...s,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 a(`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{...s,kind:`full`,configs:Object.fromEntries(this.configs)}}encodeAll(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,this.encode(n,r));return t}encode(t,n){return e(`test-config:${t}`,t,n)}},l=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 u=(e,i)=>{let a=i?.logger??t(),o=new c(a,i?.values??{});return new l(new r(`test-client`,e,{logger:a,connection:{timeout:i?.timeout}},{transport:o,telemetry:n}),o)},d=e=>u({sdkName:`nextjs-sdk`,sdkVersion:`1.13.1`},e),f=e=>{let t=globalThis.__configDirectorServerClient;return globalThis.__configDirectorServerClient=e.client,()=>{globalThis.__configDirectorServerClient=t}};export{a as ConfigDirectorConnectionError,i as ConfigDirectorValidationError,d as createTestClient,f as installServerTestClient};
1
+ import{a as e,i as t,o as n,r,t as i}from"./DefaultConfigDirectorClient-LQ79aY-g.mjs";import{a,r as o}from"./native-values-CfqV9hAq.mjs";import s from"node:events";const c=(e,t)=>({name:e.name,...t===void 0?{}:{context:t},...e.value===void 0?{}:{value:e.value},...e.details===void 0?{}:{details:e.details}});var l=class{constructor(e){this.logger=e,this.events=[]}record(e,n){switch(e.warnings.forEach(e=>this.logger.warn(t[e])),e.outcome){case`dropped`:return;case`admitted`:this.events.push(c(e.entry,n));return}}};const u={environmentId:`test-environment`,projectId:`test-project`};var d=class{constructor(e,t){this.logger=e,this.emitter=new s,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=this.encode(e,t);this.configs.set(e,n),this.deliverIfConnected({...u,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 o(`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{...u,kind:`full`,configs:Object.fromEntries(this.configs)}}encodeAll(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n,this.encode(n,r));return t}encode(e,t){return n(`test-config:${e}`,e,t)}},f=class{constructor(e,t,n){this.client=e,this.connection=t,this.trackedEvents=n}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 p=(t,n)=>{let a=n?.logger??e(),o=new d(a,n?.values??{}),s=new l(a);return new f(new i(`test-client`,t,{logger:a,connection:{timeout:n?.timeout}},{transport:o,telemetry:{...r,trackedEvent:(e,t)=>s.record(e,t)}}),o,s.events)},m=e=>p({sdkName:`nextjs-sdk`,sdkVersion:`1.14.0`},e),h=e=>{let t=globalThis.__configDirectorServerClient;return globalThis.__configDirectorServerClient=e.client,()=>{globalThis.__configDirectorServerClient=t}};export{o as ConfigDirectorConnectionError,a as ConfigDirectorValidationError,m as createTestClient,h as installServerTestClient};
2
2
  //# sourceMappingURL=testing.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.mjs","names":["createTestClient"],"sources":["../../../js-server-sdk/src/testing/InMemoryConnection.ts","../../../js-server-sdk/src/testing/TestClient.ts","../../src/server/testing.ts"],"sourcesContent":["import EventEmitter from \"node:events\";\nimport type { ConfigBundle, ConfigDefinition, ConfigDirectorLogger, Transport, TransportEvents } from \"../types\";\nimport { ConfigDirectorConnectionError } from \"@shared/errors\";\nimport type { TestValue, TestValues } from \"./values\";\nimport { unconditionalConfig } from \"../native-values\";\n\ntype Armed = \"nothing\" | \"hold\" | \"failure\";\n\ntype PendingHold = {\n end: () => void;\n complete: () => void;\n fail: () => void;\n};\n\nconst TEST_ENVIRONMENT = { environmentId: \"test-environment\", projectId: \"test-project\" };\n\nexport class InMemoryConnection implements Transport {\n private readonly emitter = new EventEmitter();\n private readonly configs = new Map<string, ConfigDefinition>();\n private readonly pendingDeliveries: ConfigBundle[] = [];\n private armed: Armed = \"nothing\";\n private pendingHold: PendingHold | undefined;\n private connected = false;\n private delivering = false;\n\n constructor(\n private readonly logger: ConfigDirectorLogger,\n values: TestValues,\n ) {\n this.encodeAll(values).forEach((definition, key) => this.configs.set(key, definition));\n }\n\n public setValue(key: string, value: TestValue) {\n const definition = this.encode(key, value);\n this.configs.set(key, definition);\n this.deliverIfConnected({ ...TEST_ENVIRONMENT, kind: \"delta\", configs: { [key]: definition } });\n }\n\n public removeValue(key: string) {\n this.configs.delete(key);\n this.deliverIfConnected(this.fullUpdate());\n }\n\n public replaceValues(values: TestValues) {\n const encoded = this.encodeAll(values);\n this.configs.clear();\n encoded.forEach((definition, key) => this.configs.set(key, definition));\n this.armed = \"nothing\";\n this.deliverIfConnected(this.fullUpdate());\n }\n\n public hold() {\n this.armed = \"hold\";\n }\n\n public complete() {\n if (this.pendingHold) {\n this.pendingHold.complete();\n } else if (this.armed === \"hold\") {\n this.armed = \"nothing\";\n }\n }\n\n public fail() {\n if (this.pendingHold) {\n this.pendingHold.fail();\n } else {\n this.armed = \"failure\";\n }\n }\n\n public connect(timeout: number): Promise<this> {\n this.endAttempt();\n const armed = this.armed;\n this.armed = \"nothing\";\n switch (armed) {\n case \"failure\":\n return this.failNow();\n case \"hold\":\n return this.holdNow(timeout);\n default:\n this.connectNow();\n return Promise.resolve(this);\n }\n }\n\n public get isConnected(): boolean {\n return this.connected;\n }\n\n public on<TName extends keyof TransportEvents>(name: TName, handler: (payload: TransportEvents[TName]) => void) {\n this.emitter.on(name, handler);\n }\n\n public off<TName extends keyof TransportEvents>(name: TName, handler?: (payload: TransportEvents[TName]) => void) {\n if (handler) {\n this.emitter.off(name, handler);\n } else {\n this.emitter.removeAllListeners(name);\n }\n }\n\n public close() {\n this.endAttempt();\n }\n\n public dispose() {\n this.close();\n this.emitter.removeAllListeners();\n }\n\n private endAttempt() {\n this.connected = false;\n this.pendingHold?.end();\n }\n\n private connectNow() {\n this.connected = true;\n this.deliver(this.fullUpdate());\n }\n\n private holdNow(timeout: number): Promise<this> {\n return new Promise<this>((resolve, reject) => {\n const timer = setTimeout(() => this.pendingHold?.end(), timeout);\n const release = () => {\n clearTimeout(timer);\n this.pendingHold = undefined;\n };\n this.pendingHold = {\n end: () => {\n release();\n resolve(this);\n },\n complete: () => {\n release();\n this.connectNow();\n resolve(this);\n },\n fail: () => {\n release();\n const error = this.fatalError();\n this.emitter.emit(\"connectionError\", error);\n reject(error);\n },\n };\n });\n }\n\n private failNow(): Promise<this> {\n const error = this.fatalError();\n this.emitter.emit(\"connectionError\", error);\n return Promise.reject(error);\n }\n\n private fatalError() {\n return new ConfigDirectorConnectionError(\n \"Connection failed with status: 401. Error: the test client failed this initialization. This is an unrecoverable error, will not attempt to reconnect.\",\n 401,\n );\n }\n\n private deliverIfConnected(configBundle: ConfigBundle) {\n if (this.connected) {\n this.deliver(configBundle);\n }\n }\n\n private deliver(configBundle: ConfigBundle) {\n this.pendingDeliveries.push(configBundle);\n if (this.delivering) {\n return;\n }\n this.delivering = true;\n try {\n let next = this.pendingDeliveries.shift();\n while (next) {\n this.emitCaught(next);\n next = this.pendingDeliveries.shift();\n }\n } finally {\n this.delivering = false;\n }\n }\n\n private emitCaught(configBundle: ConfigBundle) {\n try {\n this.emitter.emit(\"configBundleReceived\", configBundle);\n } catch (error) {\n this.logger.error(\"[InMemoryConnection] Error dispatching a config update from the test client: \", error);\n }\n }\n\n private fullUpdate(): ConfigBundle {\n return { ...TEST_ENVIRONMENT, kind: \"full\", configs: Object.fromEntries(this.configs) };\n }\n\n private encodeAll(values: TestValues): Map<string, ConfigDefinition> {\n const encoded = new Map<string, ConfigDefinition>();\n for (const [key, value] of Object.entries(values)) {\n encoded.set(key, this.encode(key, value));\n }\n return encoded;\n }\n\n private encode(key: string, value: TestValue): ConfigDefinition {\n return unconditionalConfig(`test-config:${key}`, key, value);\n }\n}\n","import { DefaultConfigDirectorClient } from \"../DefaultConfigDirectorClient\";\nimport { createDefaultLogger } from \"../logger\";\nimport type { ConfigDirectorClient, ConfigDirectorLogger, IdentifyingSdkOptions } from \"../types\";\nimport { discardingTelemetryClient } from \"../telemetry/discarding\";\nimport { InMemoryConnection } from \"./InMemoryConnection\";\nimport type { TestValue, TestValues } from \"./values\";\n\nconst TEST_CLIENT_SDK_KEY = \"test-client\";\n\n/**\n * Options for {@link createTestClient}. Every option is optional.\n */\nexport type TestClientOptions = {\n /**\n * The config values the test client serves once its client connects, keyed by config key. The\n * config type follows from each value: a boolean, an integral number (`integer`), any other\n * number (`float`), a string, or a plain object or array (`json`). Every context receives the\n * same value.\n */\n values?: TestValues;\n /**\n * The connection timeout of the SDK client, in milliseconds. It bounds how long a held\n * `initialize` waits. Defaults to the SDK's production timeout.\n */\n timeout?: number;\n /**\n * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level. Since\n * the test client sends no telemetry, every read that supplies a context with an invalid kind\n * logs an error, rather than each invalid kind once per telemetry interval.\n */\n logger?: ConfigDirectorLogger;\n};\n\n/**\n * A real ConfigDirector client connected to an in-memory server that the test controls.\n *\n * The client under {@link TestClient.client} is the SDK's production client: value parsing,\n * targeting evaluation, watchers, events, and readiness behave as they do against ConfigDirector.\n * Only the network connection and telemetry are replaced, so no request is ever made and nothing\n * is left running after the client is disposed.\n */\nexport interface TestClient {\n /**\n * The SDK client to hand to the code under test. It starts uninitialized, like a production\n * client; `initialize` completes at once with the seeded values unless initialization is held.\n */\n readonly client: ConfigDirectorClient;\n\n /**\n * Stores `value` under `key` and, when the client is connected, delivers it as an update, so\n * reads, watchers, and `configsUpdated` handlers see it.\n */\n setValue(key: string, value: TestValue): void;\n\n /**\n * Removes `key` and, when the client is connected, delivers a full update without it, so reads\n * fall back to the in-code default value and watchers of `key` receive that default.\n */\n removeValue(key: string): void;\n\n /**\n * Replaces every stored value with `values`, disarms any armed hold or failure, and, when the\n * client is connected, delivers the new values as a full update.\n */\n replaceValues(values: TestValues): void;\n\n /**\n * Makes the next `initialize` wait until {@link completeInitialization} or\n * {@link failInitialization} is called, or until the client's timeout elapses.\n */\n holdInitialization(): void;\n\n /**\n * Delivers the stored values to a held `initialize`, so it completes with the client ready. When\n * a hold is armed but no `initialize` has started, it disarms the hold instead.\n */\n completeInitialization(): void;\n\n /**\n * Fails a held `initialize` with an unrecoverable connection error, or arms the next `initialize`\n * to fail. `initialize` completes promptly with the client not ready and `connectionError` fires.\n */\n failInitialization(): void;\n}\n\nclass InMemoryTestClient implements TestClient {\n constructor(\n public readonly client: ConfigDirectorClient,\n private readonly connection: InMemoryConnection,\n ) {}\n\n public setValue(key: string, value: TestValue) {\n this.connection.setValue(key, value);\n }\n\n public removeValue(key: string) {\n this.connection.removeValue(key);\n }\n\n public replaceValues(values: TestValues) {\n this.connection.replaceValues(values);\n }\n\n public holdInitialization() {\n this.connection.hold();\n }\n\n public completeInitialization() {\n this.connection.complete();\n }\n\n public failInitialization() {\n this.connection.fail();\n }\n}\n\nexport const createTestClient = (sdkOptions: IdentifyingSdkOptions, options?: TestClientOptions): TestClient => {\n const logger = options?.logger ?? createDefaultLogger();\n const connection = new InMemoryConnection(logger, options?.values ?? {});\n const client = new DefaultConfigDirectorClient(\n TEST_CLIENT_SDK_KEY,\n sdkOptions,\n { logger, connection: { timeout: options?.timeout } },\n { transport: connection, telemetry: discardingTelemetryClient },\n );\n return new InMemoryTestClient(client, connection);\n};\n","import { createTestClient as createServerTestClient } from \"@js-server-sdk/testing/TestClient\";\nimport type { TestClient, TestClientOptions } from \"@js-server-sdk/testing/TestClient\";\n\nexport type { TestClient, TestClientOptions } from \"@js-server-sdk/testing/TestClient\";\nexport type { TestValue, TestValues, TestJsonValue } from \"@js-server-sdk/testing/values\";\nexport { ConfigDirectorConnectionError, ConfigDirectorValidationError } from \"@shared/errors\";\n\n/**\n * Creates a {@link TestClient}: a real server `ConfigDirectorClient` connected to an in-memory\n * server that the test controls. No network connection is opened and no telemetry is sent. Put it\n * where `register()` would put the server singleton with {@link installServerTestClient}.\n *\n * @param options {@link TestClientOptions}: the initial values, the client's timeout, and its logger\n * @returns A {@link TestClient} whose `client` is passed to the code under test\n *\n * @example\n * import { createTestClient, installServerTestClient } from \"@configdirector/nextjs-sdk/server/testing\";\n *\n * const testClient = createTestClient({ values: { \"new-checkout\": true } });\n * const uninstall = installServerTestClient(testClient);\n * await testClient.client.initialize();\n */\nexport const createTestClient = (options?: TestClientOptions): TestClient => {\n return createServerTestClient({ sdkName: \"nextjs-sdk\", sdkVersion: \"__VERSION__\" }, options);\n};\n\n/**\n * Puts `testClient.client` where `register()` puts the server singleton, so `getConfigClient()`,\n * `generateSsrConfigSet()`, and the server `ConfigDirectorProvider` serve its values. It does not\n * initialize the client: call `await testClient.client.initialize()`, as `register()` would.\n *\n * @param testClient The server test client whose `client` to install\n * @returns A function that restores the client installed before\n */\nexport const installServerTestClient = (testClient: TestClient): (() => void) => {\n const previous = globalThis.__configDirectorServerClient;\n globalThis.__configDirectorServerClient = testClient.client;\n return () => {\n globalThis.__configDirectorServerClient = previous;\n };\n};\n"],"mappings":"uKAcA,MAAM,EAAmB,CAAE,cAAe,mBAAoB,UAAW,eAAgB,CAEzF,IAAa,EAAb,KAAqD,CASnD,YACE,EACA,EACA,CAFiB,KAAA,OAAA,EATnB,KAAiB,QAAU,IAAI,EAC/B,KAAiB,QAAU,IAAI,IAC/B,KAAiB,kBAAoC,EAAE,CACvD,KAAQ,MAAe,UAEvB,KAAQ,UAAY,GACpB,KAAQ,WAAa,G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B,KAAM,OAAQ,QAAS,OAAO,YAAY,KAAK,QAAQ,CAAE,CAGzF,UAAkB,EAAmD,CACnE,IAAM,EAAU,IAAI,IACpB,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAO,CAC/C,EAAQ,IAAI,EAAK,KAAK,OAAO,EAAK,EAAM,CAAC,CAE3C,OAAO,EAGT,OAAe,EAAa,EAAoC,CAC9D,OAAO,EAAoB,eAAe,IAAO,EAAK,EAAM,GCxH1D,EAAN,KAA+C,CAC7C,YACE,EACA,EACA,CAFgB,KAAA,OAAA,EACC,KAAA,WAAA,EAGnB,SAAgB,EAAa,EAAkB,CAC7C,KAAK,WAAW,SAAS,EAAK,EAAM,CAGtC,YAAmB,EAAa,CAC9B,KAAK,WAAW,YAAY,EAAI,CAGlC,cAAqB,EAAoB,CACvC,KAAK,WAAW,cAAc,EAAO,CAGvC,oBAA4B,CAC1B,KAAK,WAAW,MAAM,CAGxB,wBAAgC,CAC9B,KAAK,WAAW,UAAU,CAG5B,oBAA4B,CAC1B,KAAK,WAAW,MAAM,GAI1B,MAAaA,GAAoB,EAAmC,IAA4C,CAC9G,IAAM,EAAS,GAAS,QAAU,GAAqB,CACjD,EAAa,IAAI,EAAmB,EAAQ,GAAS,QAAU,EAAE,CAAC,CAOxE,OAAO,IAAI,EANI,IAAI,EACjB,cACA,EACA,CAAE,SAAQ,WAAY,CAAE,QAAS,GAAS,QAAS,CAAE,CACrD,CAAE,UAAW,EAAY,UAAW,EAA2B,CAChE,CACqC,EAAW,ECvGtC,EAAoB,GACxB,EAAuB,CAAE,QAAS,aAAc,WAAY,SAAe,CAAE,EAAQ,CAWjF,EAA2B,GAAyC,CAC/E,IAAM,EAAW,WAAW,6BAE5B,MADA,YAAW,6BAA+B,EAAW,WACxC,CACX,WAAW,6BAA+B"}
1
+ {"version":3,"file":"testing.mjs","names":["createTestClient"],"sources":["../../../shared/src/telemetry/RecordedTrackedEvents.ts","../../../js-server-sdk/src/testing/InMemoryConnection.ts","../../../js-server-sdk/src/testing/TestClient.ts","../../src/server/testing.ts"],"sourcesContent":["import type { ConfigDirectorContext, ConfigDirectorLogger, TrackedEvent } from \"../types\";\nimport { trackedEventWarningMessages } from \"./tracked-events\";\nimport type { TrackedEventAdmission, TrackedEventEntry } from \"./tracked-events\";\n\nconst recordedEventOf = (entry: TrackedEventEntry, context: ConfigDirectorContext | undefined): TrackedEvent => ({\n name: entry.name,\n ...(context === undefined ? {} : { context }),\n ...(entry.value === undefined ? {} : { value: entry.value }),\n ...(entry.details === undefined ? {} : { details: entry.details }),\n});\n\nexport class RecordedTrackedEvents {\n public readonly events: TrackedEvent[] = [];\n\n constructor(private readonly logger: ConfigDirectorLogger) {}\n\n public record(admission: TrackedEventAdmission, context: ConfigDirectorContext | undefined): void {\n admission.warnings.forEach((warning) => this.logger.warn(trackedEventWarningMessages[warning]));\n switch (admission.outcome) {\n case \"dropped\":\n return;\n case \"admitted\":\n this.events.push(recordedEventOf(admission.entry, context));\n return;\n }\n }\n}\n","import EventEmitter from \"node:events\";\nimport type { ConfigBundle, ConfigDefinition, ConfigDirectorLogger, Transport, TransportEvents } from \"../types\";\nimport { ConfigDirectorConnectionError } from \"@shared/errors\";\nimport type { TestValue, TestValues } from \"./values\";\nimport { unconditionalConfig } from \"../native-values\";\n\ntype Armed = \"nothing\" | \"hold\" | \"failure\";\n\ntype PendingHold = {\n end: () => void;\n complete: () => void;\n fail: () => void;\n};\n\nconst TEST_ENVIRONMENT = { environmentId: \"test-environment\", projectId: \"test-project\" };\n\nexport class InMemoryConnection implements Transport {\n private readonly emitter = new EventEmitter();\n private readonly configs = new Map<string, ConfigDefinition>();\n private readonly pendingDeliveries: ConfigBundle[] = [];\n private armed: Armed = \"nothing\";\n private pendingHold: PendingHold | undefined;\n private connected = false;\n private delivering = false;\n\n constructor(\n private readonly logger: ConfigDirectorLogger,\n values: TestValues,\n ) {\n this.encodeAll(values).forEach((definition, key) => this.configs.set(key, definition));\n }\n\n public setValue(key: string, value: TestValue) {\n const definition = this.encode(key, value);\n this.configs.set(key, definition);\n this.deliverIfConnected({ ...TEST_ENVIRONMENT, kind: \"delta\", configs: { [key]: definition } });\n }\n\n public removeValue(key: string) {\n this.configs.delete(key);\n this.deliverIfConnected(this.fullUpdate());\n }\n\n public replaceValues(values: TestValues) {\n const encoded = this.encodeAll(values);\n this.configs.clear();\n encoded.forEach((definition, key) => this.configs.set(key, definition));\n this.armed = \"nothing\";\n this.deliverIfConnected(this.fullUpdate());\n }\n\n public hold() {\n this.armed = \"hold\";\n }\n\n public complete() {\n if (this.pendingHold) {\n this.pendingHold.complete();\n } else if (this.armed === \"hold\") {\n this.armed = \"nothing\";\n }\n }\n\n public fail() {\n if (this.pendingHold) {\n this.pendingHold.fail();\n } else {\n this.armed = \"failure\";\n }\n }\n\n public connect(timeout: number): Promise<this> {\n this.endAttempt();\n const armed = this.armed;\n this.armed = \"nothing\";\n switch (armed) {\n case \"failure\":\n return this.failNow();\n case \"hold\":\n return this.holdNow(timeout);\n default:\n this.connectNow();\n return Promise.resolve(this);\n }\n }\n\n public get isConnected(): boolean {\n return this.connected;\n }\n\n public on<TName extends keyof TransportEvents>(name: TName, handler: (payload: TransportEvents[TName]) => void) {\n this.emitter.on(name, handler);\n }\n\n public off<TName extends keyof TransportEvents>(name: TName, handler?: (payload: TransportEvents[TName]) => void) {\n if (handler) {\n this.emitter.off(name, handler);\n } else {\n this.emitter.removeAllListeners(name);\n }\n }\n\n public close() {\n this.endAttempt();\n }\n\n public dispose() {\n this.close();\n this.emitter.removeAllListeners();\n }\n\n private endAttempt() {\n this.connected = false;\n this.pendingHold?.end();\n }\n\n private connectNow() {\n this.connected = true;\n this.deliver(this.fullUpdate());\n }\n\n private holdNow(timeout: number): Promise<this> {\n return new Promise<this>((resolve, reject) => {\n const timer = setTimeout(() => this.pendingHold?.end(), timeout);\n const release = () => {\n clearTimeout(timer);\n this.pendingHold = undefined;\n };\n this.pendingHold = {\n end: () => {\n release();\n resolve(this);\n },\n complete: () => {\n release();\n this.connectNow();\n resolve(this);\n },\n fail: () => {\n release();\n const error = this.fatalError();\n this.emitter.emit(\"connectionError\", error);\n reject(error);\n },\n };\n });\n }\n\n private failNow(): Promise<this> {\n const error = this.fatalError();\n this.emitter.emit(\"connectionError\", error);\n return Promise.reject(error);\n }\n\n private fatalError() {\n return new ConfigDirectorConnectionError(\n \"Connection failed with status: 401. Error: the test client failed this initialization. This is an unrecoverable error, will not attempt to reconnect.\",\n 401,\n );\n }\n\n private deliverIfConnected(configBundle: ConfigBundle) {\n if (this.connected) {\n this.deliver(configBundle);\n }\n }\n\n private deliver(configBundle: ConfigBundle) {\n this.pendingDeliveries.push(configBundle);\n if (this.delivering) {\n return;\n }\n this.delivering = true;\n try {\n let next = this.pendingDeliveries.shift();\n while (next) {\n this.emitCaught(next);\n next = this.pendingDeliveries.shift();\n }\n } finally {\n this.delivering = false;\n }\n }\n\n private emitCaught(configBundle: ConfigBundle) {\n try {\n this.emitter.emit(\"configBundleReceived\", configBundle);\n } catch (error) {\n this.logger.error(\"[InMemoryConnection] Error dispatching a config update from the test client: \", error);\n }\n }\n\n private fullUpdate(): ConfigBundle {\n return { ...TEST_ENVIRONMENT, kind: \"full\", configs: Object.fromEntries(this.configs) };\n }\n\n private encodeAll(values: TestValues): Map<string, ConfigDefinition> {\n const encoded = new Map<string, ConfigDefinition>();\n for (const [key, value] of Object.entries(values)) {\n encoded.set(key, this.encode(key, value));\n }\n return encoded;\n }\n\n private encode(key: string, value: TestValue): ConfigDefinition {\n return unconditionalConfig(`test-config:${key}`, key, value);\n }\n}\n","import { DefaultConfigDirectorClient } from \"../DefaultConfigDirectorClient\";\nimport { createDefaultLogger } from \"../logger\";\nimport type { ConfigDirectorClient, ConfigDirectorLogger, IdentifyingSdkOptions } from \"../types\";\nimport type { TrackedEvent } from \"@shared/types\";\nimport { RecordedTrackedEvents } from \"@shared/telemetry/RecordedTrackedEvents\";\nimport { discardingTelemetryClient } from \"../telemetry/discarding\";\nimport { InMemoryConnection } from \"./InMemoryConnection\";\nimport type { TestValue, TestValues } from \"./values\";\n\nconst TEST_CLIENT_SDK_KEY = \"test-client\";\n\n/**\n * Options for {@link createTestClient}. Every option is optional.\n */\nexport type TestClientOptions = {\n /**\n * The config values the test client serves once its client connects, keyed by config key. The\n * config type follows from each value: a boolean, an integral number (`integer`), any other\n * number (`float`), a string, or a plain object or array (`json`). Every context receives the\n * same value.\n */\n values?: TestValues;\n /**\n * The connection timeout of the SDK client, in milliseconds. It bounds how long a held\n * `initialize` waits. Defaults to the SDK's production timeout.\n */\n timeout?: number;\n /**\n * The logger the SDK client uses. Defaults to the SDK's console logger at `warn` level. Since\n * the test client sends no telemetry, every read that supplies a context with an invalid kind\n * logs an error, rather than each invalid kind once per telemetry interval. For the same reason,\n * every tracked event that is not recorded as it was tracked logs a warning.\n */\n logger?: ConfigDirectorLogger;\n};\n\n/**\n * A real ConfigDirector client connected to an in-memory server that the test controls.\n *\n * The client under {@link TestClient.client} is the SDK's production client: value parsing,\n * targeting evaluation, watchers, events, and readiness behave as they do against ConfigDirector.\n * Only the network connection and telemetry are replaced, so no request is ever made and nothing\n * is left running after the client is disposed.\n */\nexport interface TestClient {\n /**\n * The SDK client to hand to the code under test. It starts uninitialized, like a production\n * client; `initialize` completes at once with the seeded values unless initialization is held.\n */\n readonly client: ConfigDirectorClient;\n\n /**\n * Stores `value` under `key` and, when the client is connected, delivers it as an update, so\n * reads, watchers, and `configsUpdated` handlers see it.\n */\n setValue(key: string, value: TestValue): void;\n\n /**\n * Removes `key` and, when the client is connected, delivers a full update without it, so reads\n * fall back to the in-code default value and watchers of `key` receive that default.\n */\n removeValue(key: string): void;\n\n /**\n * Replaces every stored value with `values`, disarms any armed hold or failure, and, when the\n * client is connected, delivers the new values as a full update.\n */\n replaceValues(values: TestValues): void;\n\n /**\n * Makes the next `initialize` wait until {@link completeInitialization} or\n * {@link failInitialization} is called, or until the client's timeout elapses.\n */\n holdInitialization(): void;\n\n /**\n * Delivers the stored values to a held `initialize`, so it completes with the client ready. When\n * a hold is armed but no `initialize` has started, it disarms the hold instead.\n */\n completeInitialization(): void;\n\n /**\n * Fails a held `initialize` with an unrecoverable connection error, or arms the next `initialize`\n * to fail. `initialize` completes promptly with the client not ready and `connectionError` fires.\n */\n failInitialization(): void;\n\n /**\n * Every event the code under test tracked through the client, in call order, as the SDK would\n * report it: an event whose name does not have 1 to 150 characters is not recorded, and a value\n * or details the SDK would leave out are missing from the record. A context whose kind is\n * invalid is not recorded with its event. The limit of 1,000 events per telemetry batch does not\n * apply.\n */\n readonly trackedEvents: TrackedEvent[];\n}\n\nclass InMemoryTestClient implements TestClient {\n constructor(\n public readonly client: ConfigDirectorClient,\n private readonly connection: InMemoryConnection,\n public readonly trackedEvents: TrackedEvent[],\n ) {}\n\n public setValue(key: string, value: TestValue) {\n this.connection.setValue(key, value);\n }\n\n public removeValue(key: string) {\n this.connection.removeValue(key);\n }\n\n public replaceValues(values: TestValues) {\n this.connection.replaceValues(values);\n }\n\n public holdInitialization() {\n this.connection.hold();\n }\n\n public completeInitialization() {\n this.connection.complete();\n }\n\n public failInitialization() {\n this.connection.fail();\n }\n}\n\nexport const createTestClient = (sdkOptions: IdentifyingSdkOptions, options?: TestClientOptions): TestClient => {\n const logger = options?.logger ?? createDefaultLogger();\n const connection = new InMemoryConnection(logger, options?.values ?? {});\n const recordedTrackedEvents = new RecordedTrackedEvents(logger);\n const client = new DefaultConfigDirectorClient(\n TEST_CLIENT_SDK_KEY,\n sdkOptions,\n { logger, connection: { timeout: options?.timeout } },\n {\n transport: connection,\n telemetry: {\n ...discardingTelemetryClient,\n trackedEvent: (admission, context) => recordedTrackedEvents.record(admission, context),\n },\n },\n );\n return new InMemoryTestClient(client, connection, recordedTrackedEvents.events);\n};\n","import { createTestClient as createServerTestClient } from \"@js-server-sdk/testing/TestClient\";\nimport type { TestClient, TestClientOptions } from \"@js-server-sdk/testing/TestClient\";\n\nexport type { TestClient, TestClientOptions } from \"@js-server-sdk/testing/TestClient\";\nexport type { TestValue, TestValues, TestJsonValue } from \"@js-server-sdk/testing/values\";\nexport type { TrackedEvent, TrackedEventDetails, TrackedEventDetailValue } from \"@shared/types\";\nexport { ConfigDirectorConnectionError, ConfigDirectorValidationError } from \"@shared/errors\";\n\n/**\n * Creates a {@link TestClient}: a real server `ConfigDirectorClient` connected to an in-memory\n * server that the test controls. No network connection is opened and no telemetry is sent. Put it\n * where `register()` would put the server singleton with {@link installServerTestClient}.\n *\n * @param options {@link TestClientOptions}: the initial values, the client's timeout, and its logger\n * @returns A {@link TestClient} whose `client` is passed to the code under test\n *\n * @example\n * import { createTestClient, installServerTestClient } from \"@configdirector/nextjs-sdk/server/testing\";\n *\n * const testClient = createTestClient({ values: { \"new-checkout\": true } });\n * const uninstall = installServerTestClient(testClient);\n * await testClient.client.initialize();\n */\nexport const createTestClient = (options?: TestClientOptions): TestClient => {\n return createServerTestClient({ sdkName: \"nextjs-sdk\", sdkVersion: \"__VERSION__\" }, options);\n};\n\n/**\n * Puts `testClient.client` where `register()` puts the server singleton, so `getConfigClient()`,\n * `generateSsrConfigSet()`, and the server `ConfigDirectorProvider` serve its values. It does not\n * initialize the client: call `await testClient.client.initialize()`, as `register()` would.\n *\n * @param testClient The server test client whose `client` to install\n * @returns A function that restores the client installed before\n */\nexport const installServerTestClient = (testClient: TestClient): (() => void) => {\n const previous = globalThis.__configDirectorServerClient;\n globalThis.__configDirectorServerClient = testClient.client;\n return () => {\n globalThis.__configDirectorServerClient = previous;\n };\n};\n"],"mappings":"oKAIA,MAAM,GAAmB,EAA0B,KAA8D,CAC/G,KAAM,EAAM,KACZ,GAAI,IAAY,IAAA,GAAY,EAAE,CAAG,CAAE,UAAS,CAC5C,GAAI,EAAM,QAAU,IAAA,GAAY,EAAE,CAAG,CAAE,MAAO,EAAM,MAAO,CAC3D,GAAI,EAAM,UAAY,IAAA,GAAY,EAAE,CAAG,CAAE,QAAS,EAAM,QAAS,CAClE,EAED,IAAa,EAAb,KAAmC,CAG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,GAAoB,EAAmC,IAA4C,CAC9G,IAAM,EAAS,GAAS,QAAU,GAAqB,CACjD,EAAa,IAAI,EAAmB,EAAQ,GAAS,QAAU,EAAE,CAAC,CAClE,EAAwB,IAAI,EAAsB,EAAO,CAa/D,OAAO,IAAI,EAZI,IAAI,EACjB,cACA,EACA,CAAE,SAAQ,WAAY,CAAE,QAAS,GAAS,QAAS,CAAE,CACrD,CACE,UAAW,EACX,UAAW,CACT,GAAG,EACH,cAAe,EAAW,IAAY,EAAsB,OAAO,EAAW,EAAQ,CACvF,CACF,CACF,CACqC,EAAY,EAAsB,OAAO,EC1HpE,EAAoB,GACxB,EAAuB,CAAE,QAAS,aAAc,WAAY,SAAe,CAAE,EAAQ,CAWjF,EAA2B,GAAyC,CAC/E,IAAM,EAAW,WAAW,6BAE5B,MADA,YAAW,6BAA+B,EAAW,WACxC,CACX,WAAW,6BAA+B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@configdirector/nextjs-sdk",
3
- "version": "1.13.1",
3
+ "version": "1.14.0",
4
4
  "description": "Next.js SDK for ConfigDirector. ConfigDirector is a remote configuration and feature flag service.",
5
5
  "license": "MIT",
6
6
  "author": "ConfigDirector",
@@ -1,7 +0,0 @@
1
- "use client";
2
- function e(t){"@babel/helpers - typeof";return e=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},e(t)}function t(t,n){if(e(t)!=`object`||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var i=r.call(t,n||`default`);if(e(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(n===`string`?String:Number)(t)}function n(n){var r=t(n,`string`);return e(r)==`symbol`?r:r+``}function r(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?i(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var o=class{constructor(){this.handlerMap=new Map}on(e,t){let n=this.handlerMap.get(e);n?n.push(t):this.handlerMap.set(e,[t])}once(e,t){let n=this;function r(i){n.off(e,r),t.apply(n,i)}this.on(e,r)}off(e,t){let n=this.handlerMap.get(e);if(n)if(t){let e=n.indexOf(t);e>=0&&n.splice(e,1)}else this.handlerMap.set(e,[])}clear(){this.handlerMap.clear()}emit(e,t){let n=this.handlerMap.get(e);n&&n.slice().map(e=>e(t))}},s=class e extends Error{constructor(t,n){super(t),this.name=`ConfigDirectorConnectionError`,this.status=n,Object.setPrototypeOf(this,e.prototype)}},c=class e extends Error{constructor(t){super(t),this.name=`ConfigDirectorValidationError`,Object.setPrototypeOf(this,e.prototype)}},l=class e extends Error{constructor(t){super(t),this.name=`ConfigDirectorInitializationError`,Object.setPrototypeOf(this,e.prototype)}},u=class e extends Error{constructor(t){super(t),this.name=`StreamClosedError`,Object.setPrototypeOf(this,e.prototype)}},d=class e extends Error{constructor(t){super(t),this.name=`MissingResponseBodyError`,Object.setPrototypeOf(this,e.prototype)}},f=class e extends Error{constructor(t){super(t),this.name=`InvalidOptionError`,Object.setPrototypeOf(this,e.prototype)}},p=class e extends Error{constructor(t){super(t),this.name=`ValueOutOfRangeError`,Object.setPrototypeOf(this,e.prototype)}},m=class{constructor(e){var t;this.isFirstChunk=!0,this.bufferedInput=``,this.currentEvent={data:``},this.currentEvent={data:``},this.onEvent=(t=e.onEvent)==null?(()=>{}):t,this.onRetry=e.onRetry,this.onComment=e.onComment}parse(e){let t=e;this.isFirstChunk&&(this.isFirstChunk=!1,t.startsWith(``)?t=t.slice(1):t.startsWith(``)&&(t=t.slice(3)));let n=this.scanLines(this.bufferedInput+t);for(let e of n)this.dispatchLine(e)}finish(){this.bufferedInput=``}scanLines(e){let t=[],n=0,r=0;for(;r<e.length;){let i=e[r];i===`\r`||i===`
3
- `?(t.push(e.slice(n,r)),i===`\r`&&e[r+1]===`
4
- `&&r++,r++,n=r):r++}return this.bufferedInput=e.slice(n),t}dispatchLine(e){if(e.startsWith(`:`)){var t;(t=this.onComment)==null||t.call(this,this.extractValue(e,1));return}if(e===``){this.emitEvent();return}this.applyField(this.parseField(e))}emitEvent(){let e=this.currentEvent.data.endsWith(`
5
- `)?this.currentEvent.data.slice(0,-1):this.currentEvent.data;e!==``&&this.onEvent(a(a({},this.currentEvent),{},{id:this.lastEventId,data:e})),this.currentEvent={data:``}}applyField(e){switch(e.field){case`event`:this.currentEvent.type=e.value;break;case`data`:this.currentEvent.data+=e.value+`
6
- `;break;case`id`:e.value.includes(`\0`)||(this.lastEventId=e.value);break;case`retry`:if(/^\d+$/.test(e.value)){var t;(t=this.onRetry)==null||t.call(this,Number.parseInt(e.value,10))}break;default:break}}parseField(e){let t=e.indexOf(`:`);return t===-1?{field:e,value:``}:{field:e.slice(0,t),value:this.extractValue(e,t+1)}}extractValue(e,t){return e[t]===` `?e.slice(t+1):e.slice(t)}};let h=function(e){return e.OPEN=`open`,e.CLOSED=`closed`,e.CONNECTING=`connecting`,e}({});var g=class{constructor(e){var t,n;this.DEFAULT_SHOULD_RECONNECT=()=>!0,this.DEFAULT_CALCULATE_RECONNECT_DELAY=()=>this.serverReconnectionTime,this.reconnectAttempt=0,this.abortController=new AbortController,this._readyState=h.CLOSED,this.serverReconnectionTime=2e3,this.url=e.url.toString(),this.lastEventId=e.lastEventId,this.headers=a({Accept:`text/event-stream`},e.headers);let r=e.body;this.body=typeof r==`function`?r:()=>r,this.requestOptions={method:(t=e.method)==null?`GET`:t,mode:e.mode,credentials:e.credentials,redirect:e.redirect,referrer:e.referrer,referrerPolicy:e.referrerPolicy},this._fetch=(n=e.fetch)==null?((e,t)=>fetch(e,t)):n,this._onError=this.resolveCallback(e.onError,()=>{},`onError`),this._onConnect=this.resolveCallback(e.onConnect,()=>{},`onConnect`),this._onDisconnect=this.resolveCallback(e.onDisconnect,()=>{},`onDisconnect`),this._onMessage=this.resolveCallback(e.onMessage,()=>{},`onMessage`),this._onComment=this.resolveCallback(e.onComment,()=>{},`onComment`),this._shouldReconnect=this.resolveCallback(e.shouldReconnect,this.DEFAULT_SHOULD_RECONNECT,`shouldReconnect`),this._calculateReconnectDelay=this.resolveCallback(e.calculateReconnectDelay,this.DEFAULT_CALCULATE_RECONNECT_DELAY,`calculateReconnectDelay`)}set onError(e){this._onError=this.resolveCallback(e,()=>{},`onError`)}set onMessage(e){this._onMessage=this.resolveCallback(e,()=>{},`onMessage`)}set onComment(e){this._onComment=this.resolveCallback(e,()=>{},`onComment`)}set onConnect(e){this._onConnect=this.resolveCallback(e,()=>{},`onConnect`)}set onDisconnect(e){this._onDisconnect=this.resolveCallback(e,()=>{},`onDisconnect`)}set shouldReconnect(e){this._shouldReconnect=this.resolveCallback(e,this.DEFAULT_SHOULD_RECONNECT,`shouldReconnect`)}set calculateReconnectDelay(e){this._calculateReconnectDelay=this.resolveCallback(e,this.DEFAULT_CALCULATE_RECONNECT_DELAY,`shouldReconnect`)}get readyState(){return this._readyState}connect(){this._readyState===h.CLOSED&&(this.reconnectAttempt=0,this.initiateConnection())}close(){clearTimeout(this.reconnectTimeout),this._readyState=h.CLOSED,this.abortController.abort()}initiateConnection(){this.abortController=new AbortController,this._readyState=h.CONNECTING,this._fetch(this.url,a(a({},this.requestOptions),{},{body:this.body(),headers:this.buildRequestHeaders(),signal:this.abortController.signal,cache:`no-store`})).then(e=>this.handleFetchResponse(e)).catch(e=>{if(e.name===`AbortError`||this.abortController.signal.aborted){this.close();return}this._onError(e),this.scheduleReconnect({error:e})})}async handleFetchResponse(e){var t=this;let{body:n,status:r}=e;if(r===204){t.disconnected();return}if(r>=400){t.scheduleReconnect({status:r});return}if(!n)throw new d(`The server response did not have a body`);t._readyState=h.OPEN,t._onConnect(),t.reconnectAttempt=0;let i=new m({onEvent:e=>{typeof e.id==`string`&&(t.lastEventId=e.id),t._onMessage(e)},onComment:e=>t._onComment(e),onRetry:e=>t.serverReconnectionTime=e});await t.readResponseStream(n,i),t.scheduleReconnect({status:r,error:new u(`The server response stream was closed`)})}async readResponseStream(e,t){let n=e.getReader(),r=new TextDecoder,i=!1;for(;!i;){let e=await n.read();e.value&&t.parse(r.decode(e.value,{stream:!0})),i=e.done}t.finish()}disconnected(){clearTimeout(this.reconnectTimeout),this._readyState=h.CLOSED,this._onDisconnect()}buildRequestHeaders(){let e=this.lastEventId?{"Last-Event-ID":this.lastEventId}:void 0;return a(a({},this.headers),e)}scheduleReconnect(e){if(this.abortController.signal.aborted)return;clearTimeout(this.reconnectTimeout),this.reconnectAttempt+=1;let t={attempt:this.reconnectAttempt,status:e.status,error:e.error,serverReconnectionTime:this.serverReconnectionTime};if(!this._shouldReconnect(t)){this.disconnected();return}this._readyState=h.CONNECTING;let n=this._calculateReconnectDelay(t);(!Number.isFinite(n)||n<1||n>1e3*60*60)&&(this._onError(new p(`The calculated reconnect delay is out of range: ${n}. Defaulting to ${this.serverReconnectionTime}`)),n=this.serverReconnectionTime),this.reconnectTimeout=setTimeout(()=>this.initiateConnection(),n)}resolveCallback(e,t,n){if(e==null)return t;if(typeof e!=`function`)throw new f(`${n} must be a function`);return e}};const _=e=>new g(e);var v=class{constructor(e){this.options=e,this.eventEmitter=new o,this.connectionGeneration=0,this.options=e,this.logger=e.logger,this.url=e.resolveUrl(`client/sse/v1`,e.baseUrl)}async connect(e,t){var n=this;let r=++n.connectionGeneration,i=await n.options.clientSession;if(r!==n.connectionGeneration)return n;n.eventSource&&n.close();let a=new Promise((t,r)=>{n.eventSource=_({url:n.url,method:`POST`,headers:{"Content-Type":`application/json`},fetch:n.options.fetch,body:JSON.stringify({givenContext:e,metaContext:n.options.metaContext,clientSdkKey:n.options.clientSdkKey,instanceId:i.instanceId,ephemeral:i.ephemeral}),onMessage:({data:e})=>{n.dispatchMessage(e)},onConnect:()=>{n.logger.debug(`[StreamingTransport] Connected`),t(n)},shouldReconnect:e=>{let t=!n.isStatusFatal(e.status);if(!t){let t=n.prepareFatalError(e.status,e.error);n.eventEmitter.emit(`connectionError`,t),r(t)}return t},calculateReconnectDelay:e=>{let t=n.options.connectionRetryDelay(e.attempt),r=`[StreamingTransport] Scheduling reconnect attempt #${e.attempt} in ${t}ms.`;return e.attempt<=5?n.logger.info(r):n.logger.warn(r),t},onError:e=>{n.logger.debug(`[StreamingTransport] Error: `,e)},onDisconnect:()=>{n.logger.debug(`[StreamingTransport] Disconnected`)}}),n.eventSource.connect()});return clearTimeout(n.timeoutTimer),n.timeoutTimer=void 0,Promise.race([a,new Promise(e=>{n.timeoutTimer=setTimeout(()=>e(n),t)})]).finally(()=>clearTimeout(n.timeoutTimer))}dispatchMessage(e){try{let t=JSON.parse(e);this.eventEmitter.emit(`configSetReceived`,t)}catch(e){this.logger.error(`[StreamingTransport] Error parsing and dispatching config data update: `,e)}}prepareFatalError(e,t){let n=e==null?0:e;return new s(`${`Connection failed with status: ${e==null?`unknown`:e}.`}${t?` Error: ${t}`:``}. This is an unrecoverable error, will not attempt to reconnect.`,n)}isStatusFatal(e){return!!e&&e>=400&&e<500&&e!=429}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.eventEmitter.clear()}close(){var e;this.connectionGeneration++,(e=this.eventSource)==null||e.close(),clearTimeout(this.timeoutTimer)}dispose(){this.close(),this.clear()}};const ee=(e,t)=>{if(e.trim().length==0)throw new c(`Invalid config key. The key of a value cannot be empty.`);return te(e,t)},te=(e,t)=>{switch(typeof t){case`boolean`:return{type:`boolean`,value:t?`true`:`false`};case`number`:return y(e,t);case`string`:return{type:`string`,value:t};case`object`:if(t!==null)return x(e,t,``),{type:`json`,value:JSON.stringify(t)}}throw new c(`Invalid value for '${e}': ${C(t)}. Use a boolean, a number, a string, a plain object, or an array.`)},y=(e,t)=>{if(!Number.isFinite(t))throw new c(`Invalid value for '${e}': ${C(t)} is not a finite number.`);if(Number.isInteger(t)){if(!Number.isSafeInteger(t))throw new c(`Invalid value for '${e}': ${t} is not a safe integer, so the SDK could not read it back exactly.`);return{type:`integer`,value:String(t)}}return{type:`float`,value:b(t)}},b=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}`},x=(e,t,n)=>{if(!(t===null||typeof t==`boolean`||typeof t==`string`)){if(typeof t==`number`){if(!Number.isFinite(t))throw S(e,n,`${C(t)} is not a finite number`);return}if(Array.isArray(t)){t.forEach((t,r)=>x(e,t,`${n}[${r}]`));return}if(ne(t)){for(let[r,i]of Object.entries(t))x(e,i,n?`${n}.${r}`:r);return}throw S(e,n,`${C(t)} cannot be encoded as JSON`)}},S=(e,t,n)=>new c(`Invalid value for '${e}'${t?` at '${t}'`:``}: ${n}. JSON contents can hold booleans, finite numbers, strings, null, arrays, and plain objects.`),ne=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},C=e=>{if(e===null)return`null`;if(typeof e==`function`)return`a function`;if(typeof e==`object`){var t,n;return`a ${(t=(n=e.constructor)==null?void 0:n.name)==null?`object`:t} instance`}return typeof e==`symbol`?`a symbol`:String(e)},w=(e,t,n,r)=>{let i=ee(t,n);return{id:e,key:t,type:i.type,value:i.value,valueId:r}},T={environmentId:`offline`,projectId:`offline`};var E=class{constructor(e){this.source=e,this.emitter=new o,this.on=(e,t)=>this.emitter.on(e,t),this.off=(e,t)=>this.emitter.off(e,t)}async connect(){var e=this;let t=D(e.source);return e.emitter.emit(`configSetReceived`,a(a({},T),{},{kind:`full`,configs:t})),e}clear(){this.emitter.clear()}close(){}dispose(){this.clear()}};const D=e=>{switch(e.kind){case`in-code-defaults`:return{};case`values`:return O(e.values);case`rejected`:throw new l(e.message)}},O=e=>{try{return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,w(`offline:${e}`,e,t,void 0)]))}catch(e){throw e instanceof c?new l(`The offline values could not be loaded. ${e.message}`):e}},re=(e,t,n)=>{var r;if((t==null?void 0:t.mode)===`offline`)return{kind:`stay-offline`,source:ae(t)};let i=(r=t==null?void 0:t.mode)==null?`streaming`:r;if(!e||e.trim().length==0)throw new c(`No client SDK key was provided, the client cannot be instantiated without a valid client SDK key`);return(t==null?void 0:t.values)===void 0?{kind:`connect`,mode:i,clientSdkKey:e,baseUrl:ie(t==null?void 0:t.url,n)}:{kind:`stay-offline`,source:{kind:`rejected`,message:`The connection option 'values' applies only when the connection mode is 'offline', but the mode is '${i}'.`}}},ie=(e,t)=>{if(!e)return`https://client-sdk-api.configdirector.com`;try{return t(e)}catch(t){throw new c(`Invalid base URL '${e}'. Parsing failed: ${t}`)}},ae=e=>e.values===void 0?{kind:`in-code-defaults`}:{kind:`values`,values:e.values},k=e=>{let t=typeof e;if(t===`object`)try{var n,r;return(n=(r=e.constructor)==null?void 0:r.name)==null?t:n}catch(e){return t}else if(t===`function`)try{let n=e.name;return n?`function: ${n}`:t}catch(e){return t}return t},A=e=>e===`number`||e===`bigint`,oe=new Set([`boolean`,`integer`,`float`]),j=(e,t)=>{let n=e.value,r=k(t);if(n==null||n===``)return{parsedValue:t,parsedValueId:void 0,requestedType:r,usedDefault:!0,reason:`value-missing`};if(e.type===`json`)return P(n,t,r,e.valueId);if(typeof t==`string`)return oe.has(e.type)?{parsedValue:t,parsedValueId:void 0,requestedType:r,usedDefault:!0,reason:`type-mismatch`}:{parsedValue:n,parsedValueId:e.valueId,requestedType:r,usedDefault:!1,reason:`found-match`};if(typeof t==`boolean`&&(e.type===`boolean`||e.type===`string`||e.type===`enum`)){let i=se(n),a=typeof i==`boolean`;return{parsedValue:a?i:t,parsedValueId:a?e.valueId:void 0,requestedType:r,usedDefault:!a,reason:a?`found-match`:`invalid-boolean`}}if(A(typeof t)&&e.type===`integer`){let i=ce(n),a=typeof i==`number`;return{parsedValue:a?i:t,parsedValueId:a?e.valueId:void 0,requestedType:r,usedDefault:!a,reason:a?`found-match`:`invalid-number`}}if(A(typeof t)&&(e.type===`float`||e.type===`enum`||e.type===`string`)){let i=le(n),a=typeof i==`number`;return{parsedValue:a?i:t,parsedValueId:a?e.valueId:void 0,requestedType:r,usedDefault:!a,reason:a?`found-match`:`invalid-number`}}return{parsedValue:t,parsedValueId:void 0,requestedType:r,usedDefault:!0,reason:`type-mismatch`}},se=e=>{if(!e)return;let t=e.toLowerCase();if(!(t!=`true`&&t!=`false`))return t===`true`},ce=e=>{let t=M(e);return t==null?void 0:Math.trunc(t)},le=e=>M(e),M=e=>{if(!e||!N(e))return;let t=Number(e);if(!(isNaN(t)||!isFinite(t)))return t},N=e=>{for(let t of e)if(!(t>=`0`&&t<=`9`)&&!`+-.eE`.includes(t))return!1;return!0},P=(e,t,n,r)=>{if(typeof t==`string`)return{parsedValue:e,parsedValueId:r,requestedType:n,usedDefault:!1,reason:`found-match`};try{let i=JSON.parse(e);return F(i,t)?{parsedValue:i,parsedValueId:r,requestedType:n,usedDefault:!1,reason:`found-match`}:{parsedValue:t,parsedValueId:void 0,requestedType:n,usedDefault:!0,reason:`type-mismatch`}}catch(e){return{parsedValue:t,parsedValueId:void 0,requestedType:n,usedDefault:!0,reason:`invalid-json`}}},F=(e,t)=>e===null?!1:I(e)===I(t),I=e=>{if(Array.isArray(e))return`array`;let t=typeof e;return t===`bigint`?`number`:t},L={off:-1,error:0,warn:1,info:2,debug:3},R=()=>{let e={year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,timeZoneName:`short`};try{return new Intl.DateTimeFormat(void 0,a(a({},e),{},{fractionalSecondDigits:3}))}catch(t){return new Intl.DateTimeFormat(void 0,e)}};var z=class{constructor(e,t){this.level=e,this.decorator=t,this.level=e,this.decorator=t,this.dateFormatter=R()}debug(e,...t){this.log(console.debug,`debug`,e,...t)}info(e,...t){this.log(console.info,`info`,e,...t)}warn(e,...t){this.log(console.warn,`warn`,e,...t)}error(e,...t){this.log(console.error,`error`,e,...t)}log(e,t,n,...r){if(L[this.level]>=L[t]){var i;e(`[${this.dateFormatter.format(new Date)}] ${(i=this.decorator)==null?void 0:i.decorateMessage(n)}`,...r)}}},B=class{decorateMessage(e){return`[ConfigDirector:js-client-sdk] ${e}`}};const V=(e,t)=>new z(e==null?`warn`:e,t==null?new B:t),H={updateContext:async()=>{},evaluatedConfig:()=>{},recordInvalidContext:()=>{},close:async()=>{}},U=(e,t)=>new URL(e,t==null?void 0:t.toString()),W=(e,t)=>e===void 0?{seconds:t.defaultSeconds,warning:void 0}:e>=t.minimumSeconds?{seconds:e,warning:void 0}:{seconds:t.minimumSeconds,warning:`pollingInterval of ${e} seconds is below the minimum of ${t.minimumSeconds} seconds. Using ${t.minimumSeconds} seconds.`},ue=()=>typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)}),G=e=>{try{return e(globalThis)}catch(e){return}},de=()=>G(e=>{var t;return(t=e.navigator)==null?void 0:t.userAgent}),fe=()=>G(e=>{var t;return(t=e.location)==null?void 0:t.host}),K=()=>{try{var e;return(e=globalThis.localStorage)==null?void 0:e}catch(e){return}},q=`configdirector-sdk:instance-id`,J=1e3,pe=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,Y=(e,t)=>{let n=t;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return n>>>0},X=(e,t)=>{let n=`configdirector.instanceId.v1|${e}|${t}`,r=Y(n,2166136261);return Y(`${r}|${n}`,16777619).toString(16).padStart(8,`0`)+r.toString(16).padStart(8,`0`)},me=e=>{if(!e||typeof e!=`object`)return!1;let{v:t,id:n,createdAt:r,checksum:i}=e;return t!==1||typeof n!=`string`||typeof i!=`string`||typeof r!=`number`||!Number.isInteger(r)||r<=0||!pe.test(n)?!1:i===X(n,r)},he=async(e,t)=>{let n;try{n=await e.getItem(q)}catch(e){return t.debug(`[ConfigDirectorClient] Could not read the stored instance id, using an ephemeral one`,e),{outcome:`failed`}}if(typeof n!=`string`||n===``)return{outcome:`nothing usable`};let r;try{r=JSON.parse(n)}catch(e){return t.debug(`[ConfigDirectorClient] The stored instance id is not valid JSON, generating a new one`),{outcome:`nothing usable`}}return me(r)?{outcome:`stored`,instanceId:r.id}:(t.debug(`[ConfigDirectorClient] The stored instance id failed validation, generating a new one`),{outcome:`nothing usable`})},ge=async(e,t,n)=>{let r=Date.now(),i={v:1,id:t,createdAt:r,checksum:X(t,r)};try{return await e.setItem(q,JSON.stringify(i)),!0}catch(e){return n.debug(`[ConfigDirectorClient] Could not persist the instance id, using it as an ephemeral one`,e),!1}},_e=async(e,t,n,r)=>{let i=await he(e,r);switch(i.outcome){case`stored`:return{instanceId:i.instanceId};case`failed`:return{instanceId:t,ephemeral:!0};case`nothing usable`:break}return n.passed?{instanceId:t,ephemeral:!0}:await ge(e,t,r)?{instanceId:t}:{instanceId:t,ephemeral:!0}},ve=(e,t=K())=>{let n=ue();if(!t)return e.debug(`[ConfigDirectorClient] No instance id storage is available, using an ephemeral instance id`),Promise.resolve({instanceId:n,ephemeral:!0});let r={passed:!1},i,a=new Promise(t=>{i=setTimeout(()=>{r.passed=!0,e.warn(`[ConfigDirectorClient] The instance id storage did not respond within ${J}ms, using an ephemeral instance id`),t({instanceId:n,ephemeral:!0})},J)});return Promise.race([_e(t,n,r,e),a]).finally(()=>clearTimeout(i))};var ye=class{constructor(){this.fatalError=!1}clearPollingInterval(){clearInterval(this.pollingInterval)}schedulePollingInterval(e){clearInterval(this.pollingInterval),!(this.pollingIntervalSeconds<=0)&&(this.pollingInterval=setInterval(e,this.pollingIntervalSeconds*1e3))}async handleNonOkResponse(e){var t=this;if(!e.ok)throw t.isStatusFatal(e.status)?(t.fatalError=!0,t.close(),t.prepareFatalResponseStatusError(e.status,await e.text())):new s(`Connection failed with status: ${e.status}`,e.status)}handleFetchError(e){throw this.isFetchErrorFatal(e)?(this.fatalError=!0,this.close(),new s(`Connection failed with fatal error: ${e}. This is an unrecoverable error, retry attempts will be ignored.`)):e instanceof SyntaxError?new s(`Failed to parse the response from the server: ${e}`):new s(`Connection failed with error: ${e}.`)}prepareFatalResponseStatusError(e,t){var n,r;let i=e==null?0:e;return new s(`${`Connection failed with status: ${e==null?`unknown`:e}`}${((n=t==null||(r=t.trim())==null?void 0:r.length)==null?0:n)>0?` (${t})`:``}. This is an unrecoverable error, retry attempts will be ignored.`,i)}isStatusFatal(e){return!!e&&e>=400&&e<500&&e!=429}isFetchErrorFatal(e){return(e==null?void 0:e.name)===`NotAllowedError`}get isConnected(){return this.pollingInterval!==void 0}close(){clearInterval(this.pollingInterval),this.pollingInterval=void 0}dispose(){this.close(),this.clear()}};const be=async(e,t,n,r)=>{let i=new AbortController,o=setTimeout(()=>{r.debug(`[fetchWithTimeout] Reached timeout, aborting request`),i.abort()},e);try{let e=await fetch(typeof t==`string`||t instanceof Request?t:t.toString(),a(a({},n),{},{signal:i.signal}));return clearTimeout(o),e}catch(e){throw r.warn(`[fetchWithTimeout] Fetch error: `,e),clearTimeout(o),e}};var xe=class extends ye{constructor(e){var t;super(),this.options=e,this.eventEmitter=new o,this.connectionGeneration=0,this.options=e,this.logger=e.logger,this.url=e.resolveUrl(`client/polling/v1`,e.baseUrl),this.pollingIntervalSeconds=(t=e.pollingInterval)==null?60:t}async connect(e,t){var n=this;n.endCurrentConnection();let r=n.connectionGeneration,i=await n.options.clientSession;if(r!==n.connectionGeneration)return n;try{await n.fetchConfigs(e,t,i)}finally{n.fatalError||n.schedulePollingInterval(()=>{n.fetchConfigs(e,t,i).catch(e=>{n.logger.error(`[PollingTransport] Error during polling:`,e)})})}return n}close(){this.endCurrentConnection(),super.close()}endCurrentConnection(){this.connectionGeneration++,this.clearPollingInterval(),this.lastUpdateTimestamp=void 0}async fetchConfigs(e,t,n){var r=this;if(r.fatalError){r.logger.warn(`[PollingTransport] There was a prior unrecoverable error. Ignoring attempt to reconnect.`);return}try{let i=await be(t,r.url,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({givenContext:e,metaContext:r.options.metaContext,clientSdkKey:r.options.clientSdkKey,instanceId:n.instanceId,ephemeral:n.ephemeral,lastUpdateTimestamp:r.lastUpdateTimestamp})},r.logger);if(await r.handleNonOkResponse(i),i.status==200){let e=JSON.parse(await i.text());r.lastUpdateTimestamp=e.timestamp,r.eventEmitter.emit(`configSetReceived`,e)}}catch(e){try{r.handleFetchError(e)}catch(e){throw r.fatalError&&r.eventEmitter.emit(`connectionError`,e),e}}}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.eventEmitter.clear()}};const Se=e=>e>=`a`&&e<=`z`||e>=`0`&&e<=`9`||e===`-`||e===`_`,Ce=e=>{if(e.length<1||e.length>64)return!1;for(let t of e)if(!Se(t))return!1;return!0},we=e=>e==null||typeof e==`string`&&Ce(e),Te=e=>{if(typeof e==`string`)return e;try{return String(e)}catch(t){return Object.prototype.toString.call(e)}},Ee=(e,t)=>{let n=``,r=0;for(let i of e){if(r===t)break;n+=i,r+=1}return n},De=e=>{let t=e==null?void 0:e.kind;return we(t)?{outcome:`admitted`,context:e}:{outcome:`ignored`,kindSample:Ee(Te(t),128)}},Oe=e=>e>=55296&&e<=56319,ke=e=>e>=56320&&e<=57343,Ae=e=>{let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r<=127?t+=1:r<=2047?t+=2:Oe(r)&&n+1<e.length&&ke(e.charCodeAt(n+1))?(t+=4,n++):t+=3}return t},je=`configdirector-sdk:cached-values:`,Me=256*1024,Ne=(e,t,n,r)=>{var i;if(e.kind===`stay-offline`)return{kind:`no cache`,reason:`offline mode`};if((t==null?void 0:t.enabled)===!1)return{kind:`no cache`,reason:`turned off`};if(!n)return{kind:`no cache`,reason:`no SHA-256 available`};let a=n(e.clientSdkKey),o=(i=t==null?void 0:t.provider)==null?r==null?void 0:r(a):i;return o?{kind:`cache`,provider:o,clientSdkKeyDigest:a}:{kind:`no cache`,reason:`no provider available`}},Z=(e,t)=>{var n;let r=(n=e==null?void 0:e.kind)==null?`user`:n;return(e==null?void 0:e.id)==null?{contextKind:r,anonymousInstanceId:t}:{contextKind:r,contextId:e.id}},Pe=(e,t)=>e.contextKind===t.contextKind?`contextId`in e&&`contextId`in t?e.contextId===t.contextId:`anonymousInstanceId`in e&&`anonymousInstanceId`in t?e.anonymousInstanceId===t.anonymousInstanceId:!1:!1,Fe=(e,t,n)=>n?`live values already arrived`:Pe(e.contextTag,t)?`adopt`:`context mismatch`,Q=e=>{if(!e||typeof e!=`object`)return!1;let{contextKind:t,contextId:n,anonymousInstanceId:r}=e;return typeof t==`string`?typeof n==`string`||typeof r==`string`:!1},Ie=e=>!e||typeof e!=`object`||Array.isArray(e)?!1:Object.values(e).every(e=>e&&typeof e==`object`&&typeof e.id==`string`&&typeof e.key==`string`),Le=(e,t)=>{if(!t||typeof t!=`object`)return!1;let n=t;return n.formatVersion===2&&n.clientSdkKeyDigest===e&&Q(n.contextTag)&&typeof n.environmentId==`string`&&typeof n.projectId==`string`&&Ie(n.configs)&&typeof n.receivedAt==`number`},Re=e=>!!e&&typeof e==`object`&&e.formatVersion===1,ze=(e,t)=>{let n;try{n=JSON.parse(e)}catch(e){return{outcome:`unreadable`}}return Le(t,n)?{outcome:`stored`,cachedValues:n}:Re(n)?{outcome:`first format`}:{outcome:`unreadable`}};var Be=class{constructor(e,t,n){this.provider=e,this.clientSdkKeyDigest=t,this.logger=n,this.warned=new Set,this.writing=!1}read(){return this.pendingRead!=null||(this.pendingRead=this.readEntry()),this.pendingRead}replace(e){this.queuedCachedValues=e,this.writeQueued()}async readEntry(){var e=this;let t;try{t=await e.provider.read()}catch(t){return e.warnOnce(`read failed`,`Could not read the values kept on the device, starting without them:`,t),{outcome:`failed`}}if(t==null||t===``)return{outcome:`nothing stored`};let n=ze(t,await e.clientSdkKeyDigest);switch(n.outcome){case`stored`:return n;case`first format`:return await e.removeEntry(),n;case`unreadable`:return e.warnOnce(`unreadable`,`The values kept on the device could not be read and were removed, starting without them`),await e.removeEntry(),n}}async writeQueued(){var e=this;if(!e.writing){e.writing=!0;try{for(;e.queuedCachedValues;){let t=e.queuedCachedValues;e.queuedCachedValues=void 0,await e.writeEntry(t)}}finally{e.writing=!1}}}async writeEntry(e){var t=this;let n=a({formatVersion:2,clientSdkKeyDigest:await t.clientSdkKeyDigest},e),r=JSON.stringify(n),i=Ae(r),o=t.provider.sizeLimit();if(i>o){t.warnOnce(`over the size limit`,`The values received (${i} bytes) exceed the caching provider's limit of ${o} bytes, so no values are kept on the device`),await t.removeEntry();return}try{await t.provider.write(r)}catch(e){t.warnOnce(`write failed`,`Could not keep the values on the device:`,e)}}async removeEntry(){var e=this;try{await e.provider.remove()}catch(t){e.warnOnce(`remove failed`,`Could not remove the values kept on the device:`,t)}}warnOnce(e,t,...n){this.warned.has(e)||(this.warned.add(e),this.logger.warn(`[ConfigDirectorClient] ${t}`,...n))}},Ve=class e{static from(t,n,r,i,a){return typeof n==`object`?new e(t,void 0,r,n,a):new e(t,n,r,i,a)}constructor(e,t,n,r,i){var s,c,l,u,d,f,p,m,h,g,_;this.handlersMap=new Map,this.eventEmitter=new o,this.ready=!1,this.initializing=!1,this.hasReceivedConfigSet=!1,this.servingCachedValues=!1,this.cachedValuesAdoptionStarted=!1,this.logger=(s=r==null?void 0:r.logger)==null?V():s,this.clientSession=ve(this.logger,i==null?void 0:i.instanceIdStorage),this.timeout=(c=r==null||(l=r.connection)==null?void 0:l.timeout)==null?3e3:c;let v=(u=i==null?void 0:i.urlFactory)==null?U:u;this.connectionPlan=re(t,r==null?void 0:r.connection,v),this.cachedValuesStore=this.buildCachedValuesStore(Ne(this.connectionPlan,r==null?void 0:r.caching,i==null?void 0:i.sha256HexDigest,i==null?void 0:i.platformCachingProvider)),this.telemetryClient=this.buildTelemetryClient(e,r),this.transport=(d=i==null?void 0:i.transport)==null?this.buildTransport(n,r,v,i):d,this.transport.on(`configSetReceived`,e=>{var t;this.hasReceivedConfigSet=!0,this.servingCachedValues=!1,(t=this.readyResolve)==null||t.call(this);let n=this.findKeysRemovedBy(e);!this.configSet||e.kind==`full`?this.configSet=e:this.configSet.configs=a(a({},this.configSet.configs),e.configs),this.keepValuesOnTheDevice(this.configSet);let r=Object.keys(e.configs);this.emit(`configsUpdated`,{keys:r,removedKeys:n}),this.updateWatchers([...r,...n]),this.logger.debug(`[ConfigDirectorClient] ConfigSet updated from server:`,{keys:r,removedKeys:n})}),this.transport.on(`connectionError`,e=>{this.initializing=!1,this.logger.error(`[ConfigDirectorClient] The connection encountered an unrecoverable error and will not be retried. Configs will no longer receive updates.`,e),this.emit(`connectionError`,{error:e})}),this.registerHandler(`clientReady`,r==null||(f=r.hooks)==null?void 0:f.clientReady),this.registerHandler(`configEvaluated`,r==null||(p=r.hooks)==null?void 0:p.configEvaluated),this.registerHandler(`configsUpdated`,r==null||(m=r.hooks)==null?void 0:m.configsUpdated),this.registerHandler(`contextUpdated`,r==null||(h=r.hooks)==null?void 0:h.contextUpdated),this.registerHandler(`connectionError`,r==null||(g=r.hooks)==null?void 0:g.connectionError),this.registerHandler(`cachedValuesLoaded`,r==null||(_=r.hooks)==null?void 0:_.cachedValuesLoaded)}buildCachedValuesStore(e){switch(e.kind){case`no cache`:this.logger.debug(`[ConfigDirectorClient] No values are kept on the device: ${e.reason}`);return;case`cache`:{let t=new Be(e.provider,e.clientSdkKeyDigest,this.logger);return t.read(),t}}}startCachedValuesAdoption(){let e=this.cachedValuesStore;!e||this.cachedValuesAdoptionStarted||(this.cachedValuesAdoptionStarted=!0,this.adoptCachedValues(e))}async adoptCachedValues(e){var t=this;let n=await e.read();switch(n.outcome){case`nothing stored`:case`first format`:case`unreadable`:case`failed`:return;case`stored`:break}let{instanceId:r}=await t.clientSession,i=Z(t.submittedContext,r),a=Fe(n.cachedValues,i,t.hasReceivedConfigSet);switch(a){case`adopt`:t.serveCachedValues(n.cachedValues);return;case`live values already arrived`:case`context mismatch`:t.logger.debug(`[ConfigDirectorClient] The values kept on the device were not adopted: ${a}`);return}}serveCachedValues(e){let{environmentId:t,projectId:n,configs:r}=e;this.configSet={environmentId:t,projectId:n,configs:r,kind:`full`},this.servingCachedValues=!0;let i=Object.keys(r);this.emit(`cachedValuesLoaded`,{}),this.emit(`configsUpdated`,{keys:i,removedKeys:[]}),this.updateWatchers(i),this.logger.debug(`[ConfigDirectorClient] Serving the values kept on the device until live values arrive:`,{keys:i})}keepValuesOnTheDevice(e){let t=this.cachedValuesStore;if(!t)return;let n=this.submittedContext,r=Date.now();this.clientSession.then(({instanceId:i})=>t.replace({contextTag:Z(n,i),environmentId:e.environmentId,projectId:e.projectId,configs:e.configs,receivedAt:r}))}servedReason(e){return this.servingCachedValues&&e===`found-match`?`cached`:e}registerHandler(e,t){if(!t)return;let n=Array.isArray(t)?t:[t];for(let t of n)typeof t==`function`&&this.on(e,t)}pollingIntervalFor(e,t){if(e!==`polling`)return;let n=W(t,{defaultSeconds:60,minimumSeconds:30});return n.warning&&this.logger.warn(`[ConfigDirectorClient] ${n.warning}`),n.seconds}buildTelemetryClient(e,t){let n=this.connectionPlan;switch(n.kind){case`stay-offline`:return H;case`connect`:return e({clientSdkKey:n.clientSdkKey,baseUrl:n.baseUrl,logger:this.logger,metadata:t==null?void 0:t.metadata,clientSession:this.clientSession})}}buildTransport(e,t,n,r){let i=this.connectionPlan;switch(i.kind){case`stay-offline`:return new E(i.source);case`connect`:var o,s;return new(this.getTransportConstructor(i.mode))({clientSession:this.clientSession,clientSdkKey:i.clientSdkKey,baseUrl:i.baseUrl,resolveUrl:n,metaContext:a(a({},t==null?void 0:t.metadata),{},{sdkName:e.sdkName,sdkVersion:e.sdkVersion,userAgent:de(),host:fe()}),logger:this.logger,fetch:r==null?void 0:r.fetch,connectionRetryDelay:(o=r==null?void 0:r.connectionRetryDelay)==null?(e=>2**Math.min(e,9)*1e3):o,pollingInterval:this.pollingIntervalFor(i.mode,t==null||(s=t.connection)==null?void 0:s.pollingInterval)})}}getTransportConstructor(e){switch(e){case`polling`:return xe;case`streaming`:return v}}async initialize(e){var t=this;t.hasReceivedConfigSet||(t.initializing=!0),await t.submitContext(e,`initialization`)}async updateContext(e){var t=this;switch(t.connectionPlan.kind){case`connect`:await t.submitContext(e,`context update`);return;case`stay-offline`:t.storeContext(t.admittedContextFor(e,`context update`));return}}storeContext(e){this.currentContext=e,this.emit(`contextUpdated`,{context:e})}async submitContext(e,t){var n=this;await n.connectToTransport(n.admittedContextFor(e,t),t)}admittedContextFor(e,t){let n=De(e);switch(n.outcome){case`admitted`:return n.context;case`ignored`:this.logger.error(`[ConfigDirectorClient] Ignored the context supplied for ${t} because its kind '${n.kindSample}' is invalid; continuing as if no context was supplied. A context kind has 1 to 64 characters, using only lowercase letters, digits, '-' and '_'.`),this.telemetryClient.recordInvalidContext(n.kindSample);return}}get context(){return this.currentContext}async connectToTransport(e,t){var n=this;n.submittedContext=e,t===`initialization`&&n.startCachedValuesAdoption();try{n.ready=!1,n.readyPromise=new Promise(e=>{n.readyResolve=e}).then(e=>{e||(n.ready=!0,n.initializing=!1,n.emit(`clientReady`,{action:t}),n.logger.debug(`[ConfigDirectorClient] Received initial payload from the server, client is ready`))});let r=new Date().getTime();await n.transport.connect(e==null?{}:e,n.timeout,t),n.currentContext=e,n.telemetryClient.updateContext(e).catch(e=>n.logger.warn(`[ConfigDirectorClient] Telemetry could not update the context: `,e)),n.emit(`contextUpdated`,{context:e});let i=new Date().getTime()-r,a=n.timeout-i;clearTimeout(n.timeoutTimer),n.timeoutTimer=void 0,a>0&&await Promise.race([n.readyPromise,new Promise(e=>{n.timeoutTimer=setTimeout(()=>e(),a)})]).finally(()=>clearTimeout(n.timeoutTimer)),n.ready||n.logger.warn(`[ConfigDirectorClient] Timed out waiting for ${t} after ${n.timeout}ms. ${n.timeoutWarningDetails()}`)}catch(e){if(e instanceof l)throw n.initializing=!1,e;n.logger.error(`[ConfigDirectorClient] An error occurred during ${t}: `,e)}}timeoutWarningDetails(){switch(this.connectionPlan.kind){case`connect`:return`The client will continue to retry since there were no fatal errors detected. Configs will return the default value until the connection succeeds.`;case`stay-offline`:return`The offline values were not delivered, so configs return the default value.`}}findKeysRemovedBy(e){return!this.configSet||e.kind!=`full`?[]:Object.keys(this.configSet.configs).filter(t=>!Object.prototype.hasOwnProperty.call(e.configs,t))}updateWatchers(e){e.forEach(e=>this.updateWatchersForConfig(e))}updateWatchersForConfig(e){var t,n;let r=(t=this.configSet)==null?void 0:t.configs[e];(n=this.handlersMap.get(e))==null||n.forEach(t=>{let n=this.evaluationOf(e,r,t.defaultValue).value;t.handler(n)})}watch(e,t,n){this.validateDefaultValue(t);let r=this.handlersMap.get(e),i={handler:n,defaultValue:t,requestedType:typeof t};return r?r.push(i):this.handlersMap.set(e,[i]),()=>this.unwatch(e,n)}unwatch(e,t){let n=this.handlersMap.get(e);if(n)if(t){let e=n.findIndex(e=>e.handler==t);e>=0&&(n==null||n.splice(e,1))}else n.splice(0)}getValue(e,t){return this.evaluate(e,t).value}evaluate(e,t){var n;this.validateDefaultValue(t);let r=(n=this.configSet)==null?void 0:n.configs[e];return this.evaluationOf(e,r,t)}evaluationOf(e,t,n){var r,i;if(!t){var a;this.logger.debug(`[ConfigDirectorClient] No config state found for '${e}', returning default value '${n}'`);let t=this.isReady?`config-state-missing`:`client-not-ready`;this.telemetryClient.evaluatedConfig({contextId:(a=this.currentContext)==null?void 0:a.id,key:e,defaultValue:n,requestedType:k(n),evaluatedValue:n,usedDefault:!0,evaluationReason:t});let r={key:e,value:n,isDefaultValue:!0,reason:t,context:this.context};return this.dispatchEvaluationEvent(r),r}let o=j(t,n),s=this.servedReason(o.reason);this.telemetryClient.evaluatedConfig({contextId:(r=this.currentContext)==null?void 0:r.id,type:t.type,key:e,defaultValue:n,requestedType:o.requestedType,evaluatedValue:o.parsedValue,evaluatedValueId:o.parsedValueId,usedDefault:o.usedDefault,evaluationReason:s});let c={key:e,value:o.parsedValue,valueId:(i=o.parsedValueId)==null?void 0:i,isDefaultValue:o.usedDefault,reason:s,context:this.context};return this.dispatchEvaluationEvent(c),this.logger.debug(`[ConfigDirectorClient] Evaluated '${e}' to '${o.parsedValue}'`),c}dispatchEvaluationEvent(e){setTimeout(()=>this.emit(`configEvaluated`,{evaluation:e}),0)}emit(e,t){try{this.eventEmitter.emit(e,t)}catch(t){this.logger.error(`[ConfigDirectorClient] Error executing event handlers for '${e}'`,t)}}validateDefaultValue(e){if(e==null)throw new c(`Invalid default value. The default value for a config must be defined and non-null.`);if(typeof e==`function`)throw new c(`Invalid default value. The default value for a config cannot be a function.`)}get isReady(){return this.ready}get isInitializing(){return this.initializing}on(e,t){this.eventEmitter.on(e,t)}off(e,t){this.eventEmitter.off(e,t)}clear(){this.logger.debug(`[ConfigDirectorClient] clear() has been called, removing all observers`),this.eventEmitter.clear(),this.handlersMap.clear()}unwatchAll(){this.handlersMap.clear()}pauseNetwork(){switch(this.connectionPlan.kind){case`stay-offline`:return;case`connect`:this.logger.debug(`[ConfigDirectorClient] pauseNetwork() called, pausing transport connection`),clearTimeout(this.timeoutTimer),this.timeoutTimer=void 0,this.transport.close(),this.ready=!1;return}}async resumeNetwork(){var e=this;switch(e.connectionPlan.kind){case`stay-offline`:return;case`connect`:await e.connectToTransport(e.currentContext,`network resume`);return}}async close(){var e=this,t;e.logger.debug(`[ConfigDirectorClient] close() has been called, closing connection to server`),clearTimeout(e.timeoutTimer),(t=e.readyResolve)==null||t.call(e,!0),e.telemetryClient.close().catch(t=>e.logger.warn(`[ConfigDirectorClient] Telemetry could not close: `,t)),e.transport.close(),e.ready=!1,e.initializing=!1}dispose(){this.clear(),this.close()}};const $=Symbol.for(`@configdirector/installed-test-client`),He=()=>globalThis[$];export{Me as a,H as c,w as d,s as f,a as h,je as i,V as l,o as m,He as n,K as o,c as p,Ve as r,U as s,$ as t,j as u};
7
- //# sourceMappingURL=installedTestClient-BqVnonO8.mjs.map